PHP | Ds\Vector shift() Function
Last Updated :
22 Aug, 2019
The Ds\Vector::shift() function is an inbuilt function in PHP which is used to remove the first element from the vector and return it.
Syntax:
mixed public Ds\Vector::shift( void )
Parameters: This function does not accept any parameter.
Return Value: This function returns the value at index 0.
Exception: This function throws UnderflowException if vector is empty.
Below programs illustrate the Ds\Vector::shift() function in PHP:
Program 1:
<?php
$vect = new \Ds\Vector([ "geeks" , "of" , "geeks" ]);
echo ( "First element in the vector:\n" );
var_dump( $vect ->shift());
?>
|
Output:
First element in the vector:
string(5) "geeks"
Program 2:
<?php
$vect = new \Ds\Vector([1, 2, 3, 4, 5, 6]);
var_dump( $vect ->shift());
var_dump( $vect ->shift());
var_dump( $vect ->shift());
var_dump( $vect ->shift());
?>
|
Output:
int(1)
int(2)
int(3)
int(4)
Reference: http://php.net/manual/en/ds-vector.shift.php
Share your thoughts in the comments
Please Login to comment...