PHP 如何添加到数组的末尾?
我很难添加到数组的末尾。不知道该怎么做。请帮忙。
$person = array();
$person = array("name"=>"tom", "age"=>20, "height"=>180);
如何添加到数组的末尾?我想在现有数组的末尾添加“weight”=>120。
谢谢
我很难添加到数组的末尾。不知道该怎么做。请帮忙。
$person = array();
$person = array("name"=>"tom", "age"=>20, "height"=>180);
如何添加到数组的末尾?我想在现有数组的末尾添加“weight”=>120。
谢谢
由于这是一个关联数组,因此只需执行以下操作:
$person['weight']=120;
对于常规的数字索引数组,可以使用 array_push()
或 .$person []= "new value";