开发者

How to add to array

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜