array_push() php
时间: 2023-09-19 13:06:17 浏览: 39
array_push() is a built-in PHP function that adds one or more elements to the end of an array. It takes two arguments: the first is the array to which the elements will be added, and the second is the element or elements that will be added to the array.
Here is the syntax for array_push():
```
array_push(array $array, mixed $value1 [, mixed $... ])
```
The first argument is the array to which the element(s) will be added, and the second argument can be one or more elements that will be added to the end of the array.
Here is an example of using array_push():
```
$fruits = array("apple", "banana", "orange");
array_push($fruits, "pear", "grape");
print_r($fruits);
```
Output:
```
Array
(
[0] => apple
[1] => banana
[2] => orange
[3] => pear
[4] => grape
)
```
In this example, we first create an array of three fruits. We then use array_push() to add two more fruits to the end of the array. Finally, we use print_r() to display the updated array.