PHP | Ds\Sequence pop() Function

The Ds\Sequence::pop() function is an inbuilt function in PHP which removes the last value from sequence and return it.

Syntax:

abstract public Ds\Sequence::pop( void ) : mixed

Parameters: This function does not accept any parameter.

Return Value: This function returns the popped value.

Below programs illustrate the Ds\Sequence::pop() function in PHP:



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
   
// Create new sequence
$seq =  new \Ds\Vector( [12, 15, 18, 20] );
  
// pop the sequence element
var_dump($seq->pop());
  
// pop the sequence element
var_dump($seq->pop());
  
// pop the sequence element
var_dump($seq->pop());
  
// pop the sequence element
var_dump($seq->pop());
?>

chevron_right


Output:

int(20)
int(18)
int(15)
int(12)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
   
// Create new sequence
$seq =  new \Ds\Vector([12, 15, 18, 20]);
  
for ($i = 0; $i < 4; $i++) {
  
    // Pop the sequence element
    var_dump($seq->pop());
}
  
?>

chevron_right


Output:

int(20)
int(18)
int(15)
int(12)

Reference: http://php.net/manual/en/ds-sequence.pop.php

My Personal Notes arrow_drop_up

Image
Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.