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);
精彩评论