array_unshift

Prepends passed elements to the front of the array.

Syntax

array_unshift ( array &$array [, mixed $... ] ) : int

Parameters

array

The input array.

...

The values to prepend.

Return

Returns the new number of elements in the array.

Examples

1

<?

$array = array("orange", "banana");

array_unshift($array, "apple", "raspberry");

print_r($array);

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

2

<?

$array = array("orange", "banana");

$return = array_unshift($array, "apple", "raspberry");

print_r($return);

?>
4

Internal

array_pop

array_push

array_shift

External

PHP

Home Menu