Home >Backend Development >PHP Problem >How to use Ds\Queue pop() function in PHP?

How to use Ds\Queue pop() function in PHP?

醉折花枝作酒筹
醉折花枝作酒筹forward
2021-05-31 09:44:361748browse

This article will introduce to you how to use the Ds\Queue pop() function in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

How to use Ds\Queue pop() function in PHP?

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:

<?php 
  
// Declare new Queue 
$q = new DsQueue(); 
  
// Add elements to the Queue
$q ->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 :

<?php 
  
// Declare new Queue
$q = new DsQueue(); 
  
// Add elements to the Queue
$q ->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

The above is the detailed content of How to use Ds\Queue pop() function in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete