Wednesday, November 20, 2024
Google search engine
HomeLanguagesPHP | DsSequence shift() Function

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:




<?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());
  
?>


Output:

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

Program 2:




<?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());
  
?>


Output:

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

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

RELATED ARTICLES

Most Popular

Recent Comments