<?php $data = [ 2022 => [ 'Jan' => 1, 'Mar' => 2, ] ]; $allMonths = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; foreach($data as $year => $months) { $total = 0; foreach($allMonths as $monthShort) { $monthCount = $months[$monthShort] ?? 0; $total += $monthCount; echo $monthCount, PHP_EOL; } echo 'Total:' . $total; }
You have javascript disabled. You will not be able to edit any code.