3v4l.org

run code in 300+ PHP versions simultaneously
<?php $ar = [["count"=>6,"year"=>2019,"month"=>10,"name"=>"P","id"=>3,], ["count"=>2,"year"=>2019,"month"=>10,"name"=>"s.vimal","id"=>1,], ["count"=>4,"year"=>2019,"month"=>10,"name"=>"MR","id"=>2,], ["count"=>11,"year"=>2019,"month"=>11,"name"=>"s.vimal","id"=>1,], ["count"=>1,"year"=>2019,"month"=>12,"name"=>"MR","id"=>2,], ["count"=>4,"year"=>2019,"month"=>11,"name"=>"vimaltest","id"=>10,], ["count"=>1,"year"=>2019,"month"=>12,"name"=>"vimaltest","id"=>10,]]; $mon_ar = array_unique(array_column($ar,'month')); $year_ar = array_unique(array_column($ar,'year')); foreach($ar as $rec){ foreach($year_ar as $year){ foreach($mon_ar as $month){ if (!isset($result[$year.$month])) $result[$year.$month] = [ 'month' => $month, 'year' => $year]; if ($rec['year'] == $year && $rec['month'] <= $month) { if (!isset($result[$year.$month][$rec['name']])) $result[$year.$month][$rec['name']] = 0; $result[$year.$month][$rec['name']] += $rec['count']; } } } } sort($result); print_r($result);
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
Array ( [0] => Array ( [month] => 10 [year] => 2019 [P] => 6 [s.vimal] => 2 [MR] => 4 ) [1] => Array ( [month] => 11 [year] => 2019 [P] => 6 [s.vimal] => 13 [MR] => 4 [vimaltest] => 4 ) [2] => Array ( [month] => 12 [year] => 2019 [P] => 6 [s.vimal] => 13 [MR] => 5 [vimaltest] => 5 ) )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
174.79 ms | 408 KiB | 5 Q