PHP - replace values of array with another array

后端 未结 5 1341
别那么骄傲
别那么骄傲 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:11

    If you need to preserve an order of the array, use array_replace:

        $a = array( 'a' => 1, 'b' => 2,  'c' => 3  );
        $b = array(           'b' => 20, 'c' => 30 );
    
        $r = array_replace($a, $b)
    
        // $r = array( 'a' => 1, 'b' => 20, 'c' => 30 );
    

提交回复
热议问题