array_unshift in PHP

Synatx of array_unshift

int array_unshift(array stack, mixed value1[, … mixed valueN])

Returns a copy of the given array with the additional arguments added to the beginning of the array; the added elements are added as a whole, so the elements as they appear in the array are in the same order as they appear in the argument list. Returns the number of elements in the new array.

Example of array_unshift in PHP

<?php
$queue = array("orange", "banana");
array_unshift($queue, "apple", "raspberry");
print_r($queue);
?>

Output

Array
(
    [0] => apple
    [1] => raspberry
    [2] => orange
    [3] => banana
)

Leave a Comment