$array1 = array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'); $array2 = array('key2' => 'new_value2', 'key4' => 'value4'); foreach ($array2 as $key => $value) { if (!isset($array1[$key])) { $array1[$key] = $value; } } print_r($array1);

Compare 2 arrays. Replace the missing data of 1 array with default array
Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators
More
lil-code© | 2022 - 2025
Go Top