在PHP中,可以使用array_push()
函数将元素添加到数组的末尾。例如:
$fruits = array("apple", "banana", "orange");
array_push($fruits, "grape");
这将把"grape"添加到$fruits
数组的末尾。
另外,也可以使用以下语法将元素添加到数组中:
$fruits[] = "grape";
这将在$fruits
数组的末尾添加"grape"。
如果要在数组的开头添加元素,可以使用array_unshift()
函数:
$fruits = array("apple", "banana", "orange");
array_unshift($fruits, "grape");
这将把"grape"添加到$fruits
数组的开头。
同样,也可以使用以下语法将元素添加到数组的开头:
array_unshift($fruits, "grape");
这将在$fruits
数组的开头添加"grape"。
上一篇:php对json文件的增删改查
下一篇:php 数组转stdobject
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站