How to merge two arrays by taking over only values from the second array that has the same keys as the first one?

后端 未结 3 1357
后悔当初
后悔当初 2020-12-17 23:56

I\'d like to merge two arrays with each other:

$filtered = array(1 => \'a\', 3 => \'c\');
$changed = array(2 => \'b*\', 3 => \'c*\');
         


        
3条回答
  •  Happy的楠姐
    2020-12-18 00:19

    if you want the second array ($b) to be the pattern that indicates that if there is only the key there, then you could also try this

    $new_array =  array_intersect_key( $filtered, $changed ) + $changed;
    

提交回复
热议问题