I have 2 arrays of which I am wanting to add data from one to the other in the case where the id properties of both match.
$arr1 = [['id' => 123, 'name' => 'joe'], ['id' => 321, 'name' => 'bloggo']];
$arr2 = [['id'=> 123, 'job' => 'bin man'], ['id'=> 999, 'job' => 'salary man']];
foreach($arr1 as $nameArr) {
foreach($arr2 as $jobArr) {
if ($nameArr['id'] == $jobArr['id']) {
$nameArr['job'] = $jobArr['job'];
}
}
}
echo json_encode($arr1);
This echoes the same as we see in $arr1.
I know I am missing something, I just can't wrap my head around what is missing.