array_push() function adds one or more elements to the end of the array and returns the new array length. The specific steps are as follows: Accept an array and the value to be added as parameters. Add the value to the end of the array. Returns the new array length, including newly added elements.
The role of array_push()
array_push() is a function used to add one or more items to an array. function of the element. It adds the new element to the end of the array and returns the length of the new array.
Working principle
array_push() function accepts two parameters:
If multiple values are provided, they Will be added to the array in the specified order.
Syntax
<code class="php">int array_push($array, ...$values)</code>
Return value
This function returns the length of the new array, including newly added elements.
Example
<code class="php">$arr = ['a', 'b', 'c']; array_push($arr, 'd'); // 数组变为 ['a', 'b', 'c', 'd'] echo array_push($arr, 'e', 'f'); // 输出 6,数组变为 ['a', 'b', 'c', 'd', 'e', 'f']</code>
Note
The above is the detailed content of The role of array_push in php. For more information, please follow other related articles on the PHP Chinese website!