Add one or more elements (in the stack) to the end of the array_push () array of the php array function sequence, and return the new length .. Array_push () defines and uses the array_push () function to add one or more elements (in the stack) to the end of the array of the first parameter, and then return the length of the new array. This function is equivalent to calling array_push () multiple times for definition and usage.
The array_push () function adds one or more elements (in the stack) to the end of the array of the first parameter, and returns the length of the new array.
This function is equivalent to calling $ array [] = $ value multiple times.
Syntax
Array_push (array, value1, value2...) parameter description
Array is required. Specifies an array.
Value1 is required. Specifies the value to be added.
Value2 is optional. Specifies the value to be added.
Tips and comments
Note: Even if the array contains a string key name, the element you add is always a numeric key. (See example 2)
Note: If array_push () is used to add a unit to the array, it is better to use $ array [] =, because there is no additional burden to call the function.
Note: If the first parameter is not an array, array_push () will issue a warning. This is different from the behavior of $ var []. The latter creates an array.
Example 1
The code is as follows:
$ A = array ("Dog", "Cat ");
Array_push ($ a, "Horse", "Bird ");
Print_r ($ );
?>
Output:
Array ([0] => Dog [1] => Cat [2] => Horse [3] => Bird) Example 2
Arrays with string keys:
The code is as follows:
$ A = array ("a" => "Dog", "B" => "Cat ");
Array_push ($ a, "Horse", "Bird ");
Print_r ($ );
?>
Output:
Array ([a] => Dog [B] => Cat [0] => Horse [1] => Bird)
The http://www.bkjia.com/PHPjc/324618.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/324618.htmlTechArticlearray_push () defines and uses the array_push () function to add one or more elements (in the stack) to the end of the array of the first parameter, and then returns the length of the new array. This function is called multiple times...