Compare 2 arrays. Replace the missing data of 1 array with default array

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
$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);
5

More

Leave a Reply

Your email address will not be published. Required fields are marked *

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation