The Ds\Deque::shift() function is an inbuilt function in PHP which is used to remove and return the first value of deque.
Syntax:
mixed Ds\Deque::shift( void )
Parameters: This function does not accept any parameters.
Return Value: This function returns the first value of deque which was removed.
Below programs illustrate the Ds\Deque::shift() function in PHP:
Program 1:
<?php // Declare a deque $deq = new \Ds\Deque([10, 20, 30, 40, 50, 60]); // Use Ds\Deque::shift() function var_dump( $deq -> shift()); var_dump( $deq -> shift()); var_dump( $deq -> shift()); var_dump( $deq -> shift()); var_dump( $deq -> shift()); var_dump( $deq -> shift()); ?> |
int(10) int(20) int(30) int(40) int(50) int(60)
Program 2:
<?php // Declare a deque $deq = new \Ds\Deque([ "neveropen" , "for" , "neveropen" ]); // Use Ds\Deque::shift() function var_dump( $deq -> shift()); var_dump( $deq -> shift()); var_dump( $deq -> shift()); // Declare a deque $deq = new \Ds\Deque([ 'G' , 'E' , 'E' , 'K' , 'S' , 1, 2, 3]); // Use Ds\Deque::shift() function var_dump( $deq -> shift()); var_dump( $deq -> shift()); var_dump( $deq -> shift()); ?> |
string(5) "neveropen" string(3) "for" string(5) "neveropen" string(1) "G" string(1) "E" string(1) "E"
Reference: https://www.php.net/manual/en/ds-deque.shift.php