array_unshift
int array_unshift(array array, mixed var, mixed ...)
|
array
|
Array to modify
|
|
var
|
Value to prepend to array
|
|
...
|
Further values to prepend to array
|
Pushes the list of elements onto the given array.
Returns:
Number of elements in the revised array; NULL on failure
Description:
Prepends the new elements onto array
in the order given as arguments. The first element in the argument list becomes the first element in the array. Returns the number of elements in the revised array. This function changes the original array.
Combined with array_pop(), this function can be used to make an array act in FIFO (first-in-first-out) fashion.
Version:
PHP 4
See also:
array_pop()
array_push()
array_shift()
Example:
Push values onto the beginning of an array
$arr1 = array("one", "two", "three");
$rv = array_unshift($arr1, "four", "five");
echo "New array: ", implode(", ", $arr1);
Output:
New array: four, five, one, two, three
|