3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.26, 8.0.0 - 8.0.13, 8.1rc1 - rc3
Array ( [0] => Array ( [Year] => 2020 [Month] => Feb [Account] => 225 [Analyzed] => 23 [Received] => 12 ) [1] => Array ( [Year] => 2021 [Month] => Feb [Account] => 125 [Analyzed] => 23 [Received] => 33 ) [2] => Array ( [Year] => 2022 [Month] => Feb [Account] => 425 [Analyzed] => 23 [Received] => 11 ) [3] => Array ( [Year] => 2020 [Month] => Feb [Account] => 55 [Analyzed] => 23 [Received] => 12 ) [4] => Array ( [Year] => 2021 [Month] => Feb [Account] => 33 [Analyzed] => 23 [Received] => 33 ) [5] => Array ( [Year] => 2022 [Month] => Feb [Account] => 44 [Analyzed] => 23 [Received] => 11 ) )

preferences:
32.05 ms | 463 KiB | 5 Q