In the php array function sequence, array_unshift () inserts one or more elements at the beginning of the array. Array_unshift () definition and usage the array_unshift () function inserts one or more elements at the beginning of the array. The added elements are added as a whole. The order of these elements in the array and
Array_unshift () definition and usage
The array_unshift () function inserts one or more elements at the beginning of the array.
The added elements are added as a whole. The order of these elements in the array is the same as that in the parameter.
This function returns the number of elements in the array.
Syntax
Array_unshift (array, value1, value2, value3.) parameter description
Array is required. Specifies the input array.
Value1 is required. Specifies the value to be inserted.
Value2 is optional. Specifies the value to be inserted.
Value3 is optional. Specifies the value to be inserted.
Tips and comments
Note: the names of all numeric keys are changed to count again from scratch, and the names of all string keys remain unchanged.
Example 1
The code is as follows:
$ A = array ("a" => "Cat", "B" => "Dog ");
Array_unshift ($ a, "Horse ");
Print_r ($ );
?>
Output:
Array ([0] => Horse [a] => Cat [B] => Dog) Example 2
Return key value:
The code is as follows:
$ A = array ("a" => "Cat", "B" => "Dog ");
Print_r (array_unshift ($ a, "Horse "));
?>
Output:
Example 3
The array has a numeric key:
The code is as follows:
$ A = array (0 => "Cat", 1 => "Dog ");
Array_unshift ($ a, "Horse ");
Print_r ($ );
?>
Output:
Array ([0] => Horse [1] => Cat [2] => Dog)
The http://www.bkjia.com/PHPjc/324613.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/324613.htmlTechArticlearray_unshift () definition and usage array_unshift () function inserts one or more elements at the beginning of the array. The added elements are added as a whole. The order of these elements in the array is as follows...