3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array1 = array( array('ur_user_id'=> 1,'ur_fname'=>'PerA','ur_lname'=>'SonA'), array('ur_user_id'=> 2,'ur_fname'=>'PerB','ur_lname'=>'SonB'), array('ur_user_id'=> 3,'ur_fname'=>'PerC','ur_lname'=>'SonC'), ); $array2 = array( array('ur_user_id' => 5,'ur_code' => 'AA-BB-CC','ur_user_role' => 'testE'), array('ur_user_id' => 4,'ur_code' => 'AA-BB-CC','ur_user_role' => 'testD'), array('ur_user_id' => 6,'ur_code' => 'AA-BB-CC','ur_user_role' => 'testF'), array('ur_user_id' => 3,'ur_code' => 'AA-BB-CC','ur_user_role' => 'testC'), array('ur_user_id' => 1,'ur_code' => 'AA-BB-CC','ur_user_role' => 'testA'), array('ur_user_id' => 2,'ur_code' => 'AA-BB-CC','ur_user_role' => 'testB'), ); $ids = array(); $out = array(); foreach($array1 as $key => $value){ if(isset($array2[$key])) $out[$key][] = $array2[$key]; $out[$key][] = $value; $ids[] = $array2[$key]['ur_user_id']; } foreach($array2 as $key => $val){ if(!in_array($val['ur_user_id'], $ids)) $out[$key][] = $array2[$key]; } print_r($out);
Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.6 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
Array ( [0] => Array ( [0] => Array ( [ur_user_id] => 5 [ur_code] => AA-BB-CC [ur_user_role] => testE ) [1] => Array ( [ur_user_id] => 1 [ur_fname] => PerA [ur_lname] => SonA ) ) [1] => Array ( [0] => Array ( [ur_user_id] => 4 [ur_code] => AA-BB-CC [ur_user_role] => testD ) [1] => Array ( [ur_user_id] => 2 [ur_fname] => PerB [ur_lname] => SonB ) ) [2] => Array ( [0] => Array ( [ur_user_id] => 6 [ur_code] => AA-BB-CC [ur_user_role] => testF ) [1] => Array ( [ur_user_id] => 3 [ur_fname] => PerC [ur_lname] => SonC ) ) [3] => Array ( [0] => Array ( [ur_user_id] => 3 [ur_code] => AA-BB-CC [ur_user_role] => testC ) ) [4] => Array ( [0] => Array ( [ur_user_id] => 1 [ur_code] => AA-BB-CC [ur_user_role] => testA ) ) [5] => Array ( [0] => Array ( [ur_user_id] => 2 [ur_code] => AA-BB-CC [ur_user_role] => testB ) ) )

preferences:
129.65 ms | 408 KiB | 213 Q