Open In App
Related Articles

PHP SplQueue::dequeue() Function

Improve Article
Improve
Save Article
Save
Like Article
Like

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


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 23 Jun, 2023
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials