开发者

How to add to associate array

开发者 https://www.devze.com 2023-02-04 22:15 出处:网络
I have the following array $data = array(\'key1\'=>\'val1\', \'key2\'=>\'val2\', \'key3\'=>\'val3\'

I have the following array

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

I would like to add to the开发者_Python百科 array.

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


You can use array_merge for this.

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

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


you could just use:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消