Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - replace values of array with another array

Is there a way i can replace the values of one array with the values of another which has identical keys?

$arr1 = Array
        (
            [key1] => var1
            [key2] => var2
        )
$arr2 = Array
        (
            [key1] => var3
            [key2] => var4
        )

I want to change $arr1's values to the ones in $arr2 im doing this about 10 times, and i can do it line by line, but im wondering if there's a simpler way. Thanks!

like image 833
Diesal11 Avatar asked Dec 04 '22 11:12

Diesal11


1 Answers

Check php's array_merge() function.

$arr1 = array_merge($arr1,$arr2);
like image 55
Disgone Avatar answered Dec 21 '22 10:12

Disgone