Array_push () Definition and usage
The Array_push () function adds one or more elements (into the stack) to the end of the array of the first parameter, and then returns the length of the new array.
The function equals multiple calls $array [] = $value.
Grammar
Array_push (Array,value1,value2 ...) Parameter description
Array required. Specifies an array.
Value1 required. Specifies the value to add.
value2 is optional. Specifies the value to add.
Hints and Notes
Note: Even if there are string key names in the array, the elements you add are always numeric keys. (see Example 2)
Note: If you use Array_push () to add a cell to an array, you might as well use $array [] =, because there is no additional burden of calling the function.
Note: If the first parameter is not an array, Array_push () will issue a warning. This differs from the behavior of the $var [], which creates a new array.
Example 1
The code is as follows:
<?php $a =array ("Dog", "Cat"); Array_push ($a, "Horse", "Bird"); Print_r ($a);?>
Output:
Array ([0] = Dog [1] = Cat [2] = = Horse [3] = = Bird)
Example 2
An array with a string key:
The code is as follows:
<?php $a =array ("a" and "Dog", "b" = "Cat"); Array_push ($a, "Horse", "Bird"); Print_r ($a);?>
Output:
Array ([A] = Dog [b] = Cat [0] = = Horse [1] = = Bird)
The above describes the PHP array function sequence Array_push array tail add one or more elements (into the stack), return the new length. , including the aspects of the content, want to be interested in PHP tutorial friends helpful.