php update value of array with same key -
how can update same array key new value
array ( [key1] => 3 [key2] => 2 [key3] => 1 [key4] => 2) array ( [key3] => 6 )
expected answer:
array ( [key1] => 3 [key2] => 2 [key3] => 6 [key4] => 2)
try one,
$first_array = array('key1' => 3,'key2' => 2,'key3' => 1,'key4' => 2); $second_array = array('key3' => 6); foreach ($first_array $key => $value) { if(isset($second_array[$key])) { $first_array[$key] = $second_array[$key]; } } var_dump($first_array);
Comments
Post a Comment