温馨提示×

php array_push()增加元素的方法是什么

PHP
小樊
86
2024-08-14 14:14:35
栏目: 编程语言
PHP开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

使用php的array_push()函数可以向数组的末尾添加一个或多个元素。该函数的语法如下:

array_push($array, $element1, $element2, ...)

其中,$array是要添加元素的数组,$element1, $element2等是要添加到数组末尾的元素。例如:

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

执行上述代码后,$fruits数组将包含[“apple”, “banana”, “orange”, “mango”]。

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

0