php prepend to array 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: php append to array
$myArr = [1, 2, 3, 4];
array_push($myArr, 5, 8);
print_r($myArr);
$myArr[] = -1;
print_r($myArr);
Example 3: php append element to array
array_push($cart, 13);
Example 4: php array append
<?php
$stack = array("orange", "banana");
array_push($stack, "apple", "raspberry");
print_r($stack);
?>