Skip to content
Related Articles

Related Articles

Improve Article
PHP | Ds\Deque unshift() Function
  • Last Updated : 14 Aug, 2019

The Ds\Deque::unshift() function is an inbuilt function in PHP which is used to add the value in front of the deque.

Syntax:

void Ds\Deque::unshift( $values )

Parameters: This function accepts single parameter $values which holds the values to add in the font of the deque.

Return Value: This function does not return any values.

Below programs illustrate the Ds\Deque::unshift() function in PHP:



Program 1:




<?php 
  
// Declare a deque 
$deq = new \Ds\Deque([10, 20, 30, 40]); 
  
// Use Ds\Deque::unshift() function
$deq -> unshift(5);
$deq -> unshift(7);
$deq -> unshift(8);
  
print_r($deq);
  
?> 
Output:
Ds\Deque Object
(
    [0] => 8
    [1] => 7
    [2] => 5
    [3] => 10
    [4] => 20
    [5] => 30
    [6] => 40
)

Program 2:




<?php 
  
// Declare a deque 
$deq = new \Ds\Deque(); 
  
// Use Ds\Deque::unshift() function
$deq -> unshift("Welcome");
$deq -> unshift("to");
$deq -> unshift("GeeksforGeeks");
  
var_dump($deq);
  
// Declare another deque 
$deq = new \Ds\Deque(['G', 'E', 'E', 'K', 'S']); 
  
// Use Ds\Deque::unshift() function
$deq -> unshift("1");
$deq -> unshift("2");
$deq -> unshift("3");
  
var_dump($deq);
  
?>
Output:
object(Ds\Deque)#1 (3) {
  [0]=>
  string(13) "GeeksforGeeks"
  [1]=>
  string(2) "to"
  [2]=>
  string(7) "Welcome"
}
object(Ds\Deque)#2 (8) {
  [0]=>
  string(1) "3"
  [1]=>
  string(1) "2"
  [2]=>
  string(1) "1"
  [3]=>
  string(1) "G"
  [4]=>
  string(1) "E"
  [5]=>
  string(1) "E"
  [6]=>
  string(1) "K"
  [7]=>
  string(1) "S"
}

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :