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:
<?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); ?> |
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); ?> |
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
Recommended Posts:
- Node.js | unshift() function
- PHP | SplDoublyLinkedList unshift() Function
- PHP | Ds\Sequence unshift() Function
- PHP | Ds\Vector unshift() Function
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- How to get the function name inside a function in PHP ?
- PHP | abs() Function
- p5.js | nfp() Function
- p5.js | nf() Function
- p5.js | nfc() function
- p5.js | nfs() Function
- PHP | Ds\Set last() Function
- PHP | Ds\Set add() Function
- CSS | rgb() 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.


