The syntax is as follows:
mixed public DsPriorityQueue::pop ( void )
Parameters: This function does not accept any parameters.
Return value: This function returns the current value 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 Note: If the Queue is empty, this function throws UnderflowException.
The following program illustrates the function of DsQueue::pop() in PHP:
Program 1:
push( "One" ); $q ->push( "Two" ); $q ->push( "Three" ); echo "Initial Queue is: n" ; print_r( $q ); // Pop an element echo "nPopped element is: " ; print_r( $q ->pop()); echo "nnFinal Queue is: n" ; print_r( $q ); ?>
The output is as follows:
Initial Queue is: DsQueue Object ( [0] => One [1] => Two [2] => Three ) Popped element is: One Final Queue is: DsQueue Object ( [0] => Two [1] => Three )
Program 2 :
push( "Geeks" ); $q ->push( "for" ); $q ->push( "Geeks" ); echo "Initial Queue is: n" ; print_r( $q ); // Pop an element echo "nPopped element is: " ; print_r( $q ->pop()); echo "nnFinal Queue is: n" ; print_r( $q ); ?>
The output is as follows:
Initial Queue is: DsQueue Object ( [0] => Geeks [1] => for [2] => Geeks ) Popped element is: Geeks Final Queue is: DsQueue Object ( [0] => for [1] => Geeks )
Recommended learning:php video tutorial