Syntax:void DsDeque::unshift ($values)
Parameters: This function takes one parameter, $values,which contains the values to add to the deque font.Return value:This function does not return any values. The following programs illustrate the Ds / Deque::unshift()function in PHP:Program 1:
// Declare deque
$deq
=
new
DsDeque ([10, 20, 30, 40]);
// Use the function Ds / Deque::unshift()
$deq
-> unshift (5);
$deq
-> unshift (7);
$deq
-> unshift (8);
print_r (
$deq
);
?>
Exit:DsDeque Object ( [0] = > 8 [1] = > 7 [2] = > 5 [3] = > 10 [4] = > 20 [5] = > 30 [6] = > 40)
Program 2:
// Declare deque
$deq
=
new
DsDeque();
// Use the function Ds / Deque::unshift()
$deq
-> unshift (
"Welcome"
);
$deq
-> unshift (
"to"
);
$deq
-> unshift (
"GeeksforGeeks"
);
var_dump (
$deq
);
// Declare another deck
$deq
=
new
DsDeque ([
’G’
,
’ E’
,
’E’
,
’K’
,
’ S’
]);
// Use the function Ds / Deque::unshift()
$deq
-> unshift (
"1"
);
$deq
-> unshift (
"2"
);
$deq
-> unshift (
"3"
);
var_dump (
$deq
);
?>
Exit:object (DsDeque ) # 1 (3) {[0] = > string (13) "GeeksforGeeks" [1] = > string (2) "to" [2] = > string (7) "Welcome"} object (DsDeque) # 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"}
Link: https://www.php.net/manual/en/ds-deque.unshift.php