PHP | Ds\Deque unshift() Function

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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);
  
?> 

chevron_right


Output:

Ds\Deque Object
(
    [0] => 8
    [1] => 7
    [2] => 5
    [3] => 10
    [4] => 20
    [5] => 30
    [6] => 40
)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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);
  
?>

chevron_right


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

Check out this Author's contributed articles.

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.