Home > Article > Backend Development > PHP array introductory tutorial - adding elements at the end of the array
This article introduces the method of adding elements at the end of the array in PHP array operations. Friends in need can refer to it.
To add elements to the end of the array, use the php array operation function array_push. array_push() function The return value is int type, which is the number of elements in the array after pushing the data. You can pass multiple variables as parameters to this function and push multiple variables into the array at the same time. The form is: (array array,mixed variable [,mixed variable...]) Example, two more fruits are added to the $fruits array: <?php //在数组尾添加元素 $fruits = array("apple","banana"); array_push($fruits,"orange","pear") //$fruits = array("apple","banana","orange","pear") ?> |