2009-12-25 8 views
36

연관 배열의 끝에 요소를 추가하려고합니다.PHP의 연관 배열에 값 추가

예를 들어, 내 배열은

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

하고 내 결과는

$test=Array ([chemical] => asdasd [chemical_hazards] => ggggg [solution] => good) 

당신이 어떻게 구현을 가르쳐 수 있어야한다?

$test = array('chemical' => 'asdasd', 'chemical_hazards' => 'ggggg'); //init 
$test['solution'] = 'good'; 

답변

93

은 그냥 비 연관 배열 것처럼 추가합니다.

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

당신은 PHP의 array_merge 기능이 작업을 수행 할 수 있습니다