Skip to content
Related Articles

Related Articles

Improve Article

PHP | Ds\Deque shift() Function

  • Last Updated : 14 Aug, 2019

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());
  
?> 
Output:
int(10)
int(20)
int(30)
int(40)
int(50)
int(60)

Program 2:




<?php 
  
// Declare a deque 
$deq = new \Ds\Deque(["geeks", "for", "geeks"]); 
  
// 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());
  
?>
Output:
string(5) "geeks"
string(3) "for"
string(5) "geeks"
string(1) "G"
string(1) "E"
string(1) "E"

Reference: https://www.php.net/manual/en/ds-deque.shift.php




My Personal Notes arrow_drop_up
Recommended Articles
Page :