温馨提示×

php array_push的用法是什么

PHP
小亿
76
2023-11-05 02:57:34
栏目: 编程语言
PHP开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

array_push 函数是用于向数组末尾添加一个或多个元素的方法。

语法:

array_push(array, value1, value2, ...)

参数:

  • array:必需,要添加元素的数组。
  • value1, value2, ...:可选,要添加到数组的元素。

返回值:

  • 返回添加元素后的数组的新长度。

示例:

$fruits = array("apple", "banana");
array_push($fruits, "orange", "grape");
print_r($fruits);

输出:

Array
(
    [0] => apple
    [1] => banana
    [2] => orange
    [3] => grape
)

在上面的示例中,我们将 “orange” 和 “grape” 添加到了 $fruits 数组的末尾。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:PHP array_push()函数的用法是什么

0