<?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' => 'EE','ur_user_role' => 'testE'),
array('ur_user_id' => 4,'ur_code' => 'DD','ur_user_role' => 'testD'),
array('ur_user_id' => 6,'ur_code' => 'FF','ur_user_role' => 'testF'),
array('ur_user_id' => 3,'ur_code' => 'CC','ur_user_role' => 'testC'),
array('ur_user_id' => 1,'ur_code' => 'AA','ur_user_role' => 'testA'),
array('ur_user_id' => 2,'ur_code' => 'BB','ur_user_role' => 'testB'),
);
$keyed = array_column($array2, NULL, 'ur_user_id');
foreach ($array1 as &$row) {
if (isset($keyed[$row['ur_user_id']])) {
$row += $keyed[$row['ur_user_id']];
}
}
var_export($array1);
- Output for 5.6.40, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- array (
0 =>
array (
'ur_user_id' => 1,
'ur_fname' => 'PerA',
'ur_lname' => 'SonA',
'ur_code' => 'AA',
'ur_user_role' => 'testA',
),
1 =>
array (
'ur_user_id' => 2,
'ur_fname' => 'PerB',
'ur_lname' => 'SonB',
'ur_code' => 'BB',
'ur_user_role' => 'testB',
),
2 =>
array (
'ur_user_id' => 3,
'ur_fname' => 'PerC',
'ur_lname' => 'SonC',
'ur_code' => 'CC',
'ur_user_role' => 'testC',
),
)
preferences:
132.03 ms | 409 KiB | 5 Q