PHP - replace values of array with another array

后端 未结 5 1356
别那么骄傲
别那么骄傲 2021-01-19 14:56

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

$arr1 = Array
        (
            [key1] => va         


        
5条回答
  •  感动是毒
    2021-01-19 15:19

    Simply use the replace function.

    $arr1 = array_replace($arr1, $arr2);
    

    or better of if you want to deal with multi-dimensional array, use recursive replace.

    $arr1 = array_replace_recursive($arr1, $arr2);
    

    For details check these links array_replace(), array_replace_recursive()

提交回复
热议问题