array_unshift() function is used to insert new elements into the array and return the number of elements in the new array. The values of the new array will be inserted at the beginning of the array.
(Recommended tutorial:php graphic tutorial)
Tip: You can insert one or more values. Numeric key names will start at 0 and increase by 1. String key names will remain unchanged.
Function syntax:
array_unshift(array,value1,value2,value3...)
Parameter description:
array Required. Specifies an array.
#value1 Required. Specifies the value to be inserted.
#value2 Optional. Specifies the value to be inserted.
#value3 Optional. Specifies the value to be inserted.
(Learning video recommendation:php video tutorial)
Example:
"red","b"=>"green"); array_unshift($a,"blue"); print_r($a); ?>
Run result:
Array ( [0] => blue [a] => red [b] => green )
The above is the detailed content of Detailed explanation of php array_unshift() function (example). For more information, please follow other related articles on the PHP Chinese website!