Skip to content
Related Articles

Related Articles

PHP | SplQueue::dequeue() Function
  • Last Updated : 23 Aug, 2019

The SplQueue::dequeue() function is an inbuilt function in PHP which is used to dequeues the node from the queue.

Syntax:

mixed SplQueue::dequeue()

Parameters: This function does not accept any parameter.

Return Value: This function return the value of the dequeued node.

Below programs illustrate the SplQueue::dequeue() function in PHP:



Program 1:




<?php
  
// Create a new empty queue
$gfg = new SplQueue();
  
$gfg[] = 1;
$gfg[] = 2;
$gfg[] = 3;
  
// Dequeue element
echo $gfg->dequeue() . "\n";
echo $gfg->dequeue() . "\n";
  
?>
Output:
1
2

Program 2:




<?php
  
// Create some fixed size array
$gfg = new SplQueue();
  
$gfg[] = 1;
$gfg[] = 5;
$gfg[] = 1;
$gfg[] = 11;
$gfg[] = 15;
$gfg[] = 17;
  
foreach ($gfg as $elem)  {
    echo $elem . "\n";
}
  
$gfg->dequeue();
$gfg->dequeue();
$gfg->dequeue();
  
// Print result after dequeue
foreach ($gfg as $elem)  {
    echo "dequeue: " . $gfg->dequeue() . "\n";
  
}
?>
Output:
1
5
1
11
15
17
dequeue: 11
dequeue: 15
dequeue: 17

Reference: https://www.php.net/manual/en/splqueue.dequeue.php

My Personal Notes arrow_drop_up
Recommended Articles
Page :