Definition
The array_unshift()
function inserts one or more elements at the beginning of an array.
All numerical array keys will be modified to start counting from zero. String keys will remain the same.
The basic syntax of the array_unshift()
function is given with:
array_unshift(array, value1, value2, ...);
The array_unshift()
function accepts the following parameters.
Parameter | Description |
---|---|
array | Required. Specifies the array to work on. |
value1, value2, ... | Optional. Specifies the values to prepend to the beginning of the array. |
Example1 : Insert element "web" ,"designing" to an array.
Output :
Array
(
[0] => web
[1] => designing
[2] => house
[3] => online
[4] => promotiion
)
Example2 : for associative arrays as demonstrated below
Output :
Array
(
[0] => web
[a] => designing
[b] => house
[c] => online
[d] => promotiion
)