开发者

How to add to array

开发者 https://www.devze.com 2023-01-13 18:29 出处:网络
I need to add some new values to array by doing something similar. $array = array(); $array[7] = \'test1\';

I need to add some new values to array by doing something similar.

$array = array();
$array[7] = 'test1';
$array[7] = 'test2';

The problem is that [7] only takes the last value 开发者_高级运维that was added and not test1.


Declare a new (sub)array at the desired offset, and use [] to append new elements to it:

$array = array();
$array[7] = array();
$array[7][] = 'test1';
$array[7][] = 'test2';
print_r($array);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号