<?php
$sorted = [
[
['Year' => "2020", 'Month' => "Feb", 'Analyzed' => 23, 'Account' => 225,],
['Year' => "2021", 'Month' => "Feb", 'Analyzed' => 23, 'Account' => 125,],
['Year' => "2022", 'Month' => "Feb", 'Analyzed' => 23, 'Account' => 425,],
],
[
['Year' => "2020", 'Month' => "Feb", 'Analyzed' => 23, 'Account' => 55,],
['Year' => "2021", 'Month' => "Feb", 'Analyzed' => 23, 'Account' => 33,],
['Year' => "2022", 'Month' => "Feb", 'Analyzed' => 23, 'Account' => 44,],
],
];
$sorted_Rcv = [
[
['Year' => "2020", 'Month' => "Feb", 'Received' => 12, 'Account' => 225,],
['Year' => "2021", 'Month' => "Feb", 'Received' => 33, 'Account' => 125,],
['Year' => "2022", 'Month' => "Feb", 'Received' => 11, 'Account' => 425,],
],
[
['Year' => "2020", 'Month' => "Feb", 'Received' => 12, 'Account' => 55,],
['Year' => "2021", 'Month' => "Feb", 'Received' => 33, 'Account' => 33,],
['Year' => "2022", 'Month' => "Feb", 'Received' => 11, 'Account' => 44,],
],
];
$merged_result = array();
foreach($sorted as $subar1){
foreach($subar1 as $val){
foreach($sorted_Rcv as $subar2){
foreach($subar2 as $val2){
if ($val['Year'] == $val2['Year'] && $val['Month'] == $val2['Month'] && $val['Account'] == $val2['Account']){
$merged_result[] = [
'Year' => $val2['Year'],
'Month' => $val2['Month'],
'Account' => $val2['Account'],
'Analyzed' => $val['Analyzed'],
'Received' => $val2['Received'],
];
}
}
}
}
}
print_r($merged_result);
preferences:
55.46 ms | 402 KiB | 5 Q