The Ds\Queue::pop() Function in PHP is used to remove and return the value present at the top of the Queue. In other words, it returns the value present at the front of the Queue and also removes it from the Queue.
Syntax:
mixed public Ds\Queue::pop ( void )
Parameters: This function does not accepts any parameters.
Return Value: This function returns the value with present at the top of the Queue. The return type of the function is mixed and depends on the type of value stored in the Queue.
Exception: This function throws an Underflow Exception if the Queue is empty.
Below programs illustrate the Ds\Queue::pop() Function in PHP:
Program 1:
PHP
<?php
$q = new \Ds\Queue();
$q ->push( "One" );
$q ->push( "Two" );
$q ->push( "Three" );
echo "Initial Queue is: \n" ;
print_r( $q );
echo "\nPopped element is: " ;
print_r( $q ->pop());
echo "\n\nFinal Queue is: \n" ;
print_r( $q );
?>
|
Output: Initial Queue is:
Ds\Queue Object
(
[0] => One
[1] => Two
[2] => Three
)
Popped element is: One
Final Queue is:
Ds\Queue Object
(
[0] => Two
[1] => Three
)
Program 2:
PHP
<?php
$q = new \Ds\Queue();
$q ->push( "Geeks" );
$q ->push( "for" );
$q ->push( "Geeks" );
echo "Initial Queue is: \n" ;
print_r( $q );
echo "\nPopped element is: " ;
print_r( $q ->pop());
echo "\n\nFinal Queue is: \n" ;
print_r( $q );
?>
|
Output: Initial Queue is:
Ds\Queue Object
(
[0] => Geeks
[1] => for
[2] => Geeks
)
Popped element is: Geeks
Final Queue is:
Ds\Queue Object
(
[0] => for
[1] => Geeks
)
Reference: http://php.net/manual/en/ds-queue.pop.php