开发者

array_push into a multi-dimensional array

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?

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开发者_JS百科 into a array with key value?

Thanks for any help you can offer,

--Bryan


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'] = array('some string');

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜