unshift php code example
Example 1: php add element to array first position
<?php
$queue = array("orange", "banana");
array_unshift($queue, "apple", "raspberry");
print_r($queue);
?>
Array
(
[0] => apple
[1] => raspberry
[2] => orange
[3] => banana
)
Example 2: array unshift php
<?php
$a=array("a"=>"red","b"=>"green");
array_unshift($a,"blue");
print_r($a);
?>
Example 3: unshift in php
<?php
$a=array("a"=>"red","b"=>"green");
array_unshift($a,"blue");
print_r($a);
// result : Array ( [0] => blue [a] => red [b] => green )
?>