The usage of array_push in php is [array_push(array, value1, value2...)]. The array_push function adds one or more elements to the end of an array and returns the length of the new array.
The operating environment of this article: windows10 system, php 7.3, thinkpad t480 computer.
array_push() function adds one or more elements (push) to the end of the array of the first parameter, and then returns the length of the new array.
Even if there are string key names in the array, the elements you add are always numeric keys.
Usage:
array_push(array,value1,value2...)
Let’s give an example:
<!DOCTYPE html> <html> <body> <?php $a=array("red","green"); array_push($a,"blue","yellow"); print_r($a); ?> </body> </html>
Let’s see the running effect:
Array ( [0] => red [1] => green [2] => blue [3] => yellow )
Related video tutorial sharing: php video tutorial
The above is the detailed content of What is the usage of array_push in php. For more information, please follow other related articles on the PHP Chinese website!