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 front 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
<?php
$deq = new \Ds\Deque([10, 20, 30, 40]);
$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
<?php
$deq = new \Ds\Deque();
$deq -> unshift("Welcome");
$deq -> unshift("to");
$deq -> unshift("GeeksforGeeks");
var_dump( $deq );
$deq = new \Ds\Deque([ 'G' , 'E' , 'E' , 'K' , 'S' ]);
$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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
20 Mar, 2023
Like Article
Save Article