6

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 into a array with key value?

Thanks for any help you can offer,

--Bryan

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
bryan sammon
  • 7,161
  • 15
  • 38
  • 48

1 Answers1

10

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';
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356