Array_push to a multidimensional array

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

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

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

Ive tried this:

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

and I tried another obvious way, but nothing works. Is it possible to add array_push to an array with a key?

Thanks for any help you can offer.

- Bryan

+6
arrays php multidimensional-array
source share
1 answer

If you want $some_array['array_key'] be an array of values, you must initialize it as an array, for example:

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

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

 $some_array['array_key'][] = 'another string'; 
+9
source share

All Articles