<?php
$first = array (
0 => array (
'id' => 5,
'name' => 'Education'
),
1 => array (
'id' => 4,
'name' => 'Computers'
),
3 => array (
'id' => 7,
'name' => 'Science'
),
4 => array (
'id' => 1,
'name' => 'Sports'
),
);
$second = array (
0 => array (
'id' => 1,
'title' => 'Sport'
),
1 => array (
'id' => 7,
'title' => 'Sci'
),
3 => array (
'id' => 4,
'title' => 'Comp'
),
4 => array (
'id' => 5,
'title' => 'Edu'
),
);
$second = array_column($second, null, 'id');
foreach ($first as &$subject) {
$subject += $second[$subject['id']] ?? [];
}
print_r($first);
preferences:
24.44 ms | 405 KiB | 5 Q