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

1 Answer 1

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';
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.