PHP | Ds\Vector shift() Function
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 // Declare an Vector $vect = new \Ds\Vector(["geeks", "of", "geeks"]); echo("First element in the vector:\n"); // Use shift() function to remove first // element from vector and display it var_dump($vect->shift()); ?> |
Output:
First element in the vector: string(5) "geeks"
Program 2:
<?php // Declare an Vector $vect = new \Ds\Vector([1, 2, 3, 4, 5, 6]); // Use shift() function to remove first // element from vector and display it 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
Recommended Posts:
- PHP | Ds\Deque shift() Function
- Node.js | shift() function
- PHP | Ds\Sequence shift() Function
- PHP | SplDoublyLinkedList shift() Function
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- PHP | sin( ) Function
- D3.js | d3.map.set() Function
- PHP | abs() Function
- D3.js | d3.min() function
- PHP | cos( ) Function
- D3.js | d3.max() function
- PHP | Ds\Map xor() Function
- PHP | end() Function
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.



