<?php $db = [ ['dates' => 'Sep-2022', 'income' => 1864], ['dates' => 'Oct-2022', 'income' => 548] ]; $lookup = array_column($db, null, 'dates'); $year = date('Y'); for ($i = 1; $i < 13 ; ++$i) { $date = date('M-Y', strtotime("$year-$i-01")); $months[] = $lookup[$date] ?? ['dates' => $date, 'income' => 0]; } var_export($months);
You have javascript disabled. You will not be able to edit any code.