How does PHP use the DS \ queue pop() function? Usage code example

Time:2021-9-17

The function in dsqueue:: pop() PHP is used to delete and return the value that appears at the top of the queue. In other words, it returns the value that appears in front of the queue and removes it from the queue.

The syntax is as follows:

mixed public DsPriorityQueue::pop ( void )

Arguments: this function does not accept any arguments.

Return value: this function returns the present value of 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 raises underflowexception.

The following program describes the functions in dsqueue:: pop() PHP:

Procedure 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
)

reference resources:http://php.net/manual/en/ds-q…

For more information about PHP development, please refer to:Lsbin – it development technologyhttps://www.lsbin.com/

See more about PHP:

Recommended Today

Seven Python code review tools recommended

althoughPythonLanguage is one of the most flexible development languages at present, but developers often abuse its flexibility and even violate relevant standards. So PythoncodeThe following common quality problems often occur: Some unused modules have been imported Function is missing arguments in various calls The appropriate format indentation is missing Missing appropriate spaces before and after […]