I need to combine two multi-dimensional arrays in order to produce a single merged array.
Array 1 ($array1
) is sorted by the key value 'vo'. I need to attach a second array ($array2
) to the first array with same userID.
For example:
$array1 = array(
1 => array(
'id' => 1,
'vo' => 1,
'userID' => 21
),
2 => array(
'id' => 2,
'vo' => 2,
'userID' => 22
),
3 => array(
'id' => 3,
'vo' => 3,
'userID' => 23
),
4 => array(
'id' => 4,
'vo' => 5,
'userID' => 25
)
);
Second array:
$array2 = array(
1 => array(
'id' => 1,
'userID' => 21
),
2 => array(
'id' => 2,
'userID' => 21
),
3 => array(
'id' => 3,
'userID' => 23
)
);
Desired solution:
$desired_solution = array(
1 => array(
'id' => 1,
'vo' => 1,
'userID' => 21
),
2 => array(
'id' => 1,
'userID' => 21
),
3 => array(
'id' => 2,
'userID' => 21
),
4 => array(
'id' => 2,
'vo' => 2,
'userID' => 22
),
5 => array(
'id' => 3,
'vo' => 3,
'userID' => 23
),
6 => array(
'id' => 3,
'userID' => 23
),
...
);