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
  • 665,005
  • 155
  • 1,345
  • 1,328
bryan sammon
  • 6,821
  • 12
  • 36
  • 46

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
  • 665,005
  • 155
  • 1,345
  • 1,328