扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

php array_push的用法是什么

扬州沐宇科技
2023-11-05 02:57:34
PHP

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 数组的末尾。

扫码添加客服微信