PHP | Ds\Sequence shift() Function

The Ds\Sequence::shift() function is an inbuilt function in PHP which is used to removes the first element from the sequence and return it.

Syntax:

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

Parameters: This function does not accepts any parameter.



Return values: This function returns the first value which is removed from the sequence.

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

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
   
// Create new sequence
$seq new \Ds\Vector([9, 10, 15, 20]);
  
// Use shift() function to remove
// first element from sequence
var_dump($seq->shift());
  
var_dump($seq->shift());
  
var_dump($seq->shift());
  
var_dump($seq->shift());
  
?>

chevron_right


Output:

int(9)
int(10)
int(15)
int(20)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
   
// Create new sequence
$seq new \Ds\Vector(["Geeks", "for", "Geeks"]);
  
// Use shift() function to remove
// first element from sequence
var_dump($seq->shift());
  
var_dump($seq->shift());
  
var_dump($seq->shift());
  
?>

chevron_right


Output:

string(5) "Geeks"
string(3) "for"
string(5) "Geeks"

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



My Personal Notes arrow_drop_up

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.