search
HomeBackend DevelopmentPHP ProblemHow to use Ds\Queue pop() function in PHP?

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

May 31, 2021 am 09:44 AM
phpqueuedata structurequeue

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. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor