Add values to an associative array in PHP

前端 未结 2 1012
花落未央
花落未央 2020-12-29 18:26

I want to append an element to to end of an associative array.

For example, my array is

$test=Array ([chemical] => asdasd [chemical_hazards] =>         


        
2条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 19:17

    You can do this with PHP's array_merge function.

    $test = array('chemical' => 'asdasd', 'chemical_hazards' => 'ggggg'); 
    $test2 = array('solution' => 'good');
    $result = array_merge($test, $test2);
    var_dump($result);
    

提交回复
热议问题