3

I have the following array

$data = array('key1'=>'val1',
              'key2'=>'val2',
              'key3'=>'val3'
             );

I would like to add to the array.

$moreval = array('key4'=>'val4');

2 Answers 2

1

You can use array_merge for this.

$data=array_merge($data, array('key4'=>'val4'));

If this wasn't associative, you could use array_push.

0

you could just use:

$data['key4'] = 'val4';

Not the answer you're looking for? Browse other questions tagged or ask your own question.