array_push成为一个多维数组

时间:2021-11-03 21:38:13

I have a array with a key value you on it like:

我有一个关键值的数组,如:

$some_array['array_key'] = "some string";

Is it possible to use array_push to add more elements to the array?

是否可以使用array_push向数组添加更多元素?

Ive tried this:

我试过这个:

array_push($some_array['array_key'],"another string");

and I have tried other obvious way, but nothing seems to work. Is it possible to add array_push into a array with key value?

我尝试过其他明显的方法,但似乎没有任何效果。是否可以将array_push添加到具有键值的数组中?

Thanks for any help you can offer,

谢谢你尽你所能的帮助,

--Bryan

1 个解决方案

#1


9  

If you want $some_array['array_key'] to be an array of values, you have to initialize it as an array, like this:

如果你想$ some_array ['array_key']是一个值数组,你必须将它初始化为一个数组,如下所示:

$some_array['array_key'] = array('some string');

Only then can you use array_push() or the [] = notation:

只有这样才能使用array_push()或[] =表示法:

$some_array['array_key'][] = 'another string';

#1


9  

If you want $some_array['array_key'] to be an array of values, you have to initialize it as an array, like this:

如果你想$ some_array ['array_key']是一个值数组,你必须将它初始化为一个数组,如下所示:

$some_array['array_key'] = array('some string');

Only then can you use array_push() or the [] = notation:

只有这样才能使用array_push()或[] =表示法:

$some_array['array_key'][] = 'another string';