php array push
时间: 2023-02-07 15:25:20 浏览: 104
array_push() 函数向数组末尾添加一个或多个元素。
用法:
array_push(array, value1, value2, ...)
例如:
$fruits = array("apple", "banana");
array_push($fruits, "orange", "mango");
print_r($fruits);
输出:
Array ( [0] => apple [1] => banana [2] => orange [3] => mango )
相关问题
php array_push
array_push() 函数用于向数组的末尾添加一个或多个元素。它会修改原始数组,并返回新数组的长度。
array_push() 函数的语法如下:
```
array_push(array, value1, value2, ...)
```
其中,array 是要添加元素的数组,value1、value2 等是要添加的元素。
以下是 array_push() 函数的一些特点:
- 可以一次向数组添加多个元素。
- 添加的元素会按照添加的顺序排列在数组的末尾。
- 如果添加的元素是一个数组,它将作为一个整体添加到原始数组中。
下面是一个示例,演示了如何使用 array_push() 函数向数组中添加元素:
```php
$fruits = array("apple", "banana");
array_push($fruits, "orange", "grape");
print_r($fruits);
```
输出结果为:
```
Array
(
[0] => apple
[1] => banana
[2] => orange
[3] => grape
)
```
array_push() php
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.
阅读全文