PHP array_unshift() Function
The array_unshift() is used to add one or more elements to the beginning of an array.
Tip: You can add one value, or as many as you like.
Note: Numeric keys will start at 0 and increase by 1. String keys will remain the same.
Parameter | Description |
---|---|
array | Required. Specifying an array |
value1 | Required. Specifies a value to insert |
value2 | Optional. Specifies a value to insert |
value3 | Optional. Specifies a value to insert |
Syntax
array_unshift(array,value1,value2,value3...)
Example
$array = array("a"=>"Cooper","b"=>"Samuel");
array_unshift($array,"James");
print_r($array);
Output
Array ( [0] => James [a] => Cooper [b] => Samuel )
Leave a Reply