3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function getMonths($begin, $end) { $monthsData = array(); $dateBegin = new \DateTime($begin); $dateEnd = new \DateTime($end); while ($dateBegin->getTimestamp() < $dateEnd->getTimestamp()) { $monthsData[] = $dateBegin->format('m/Y'); $dateBegin->add(new \DateInterval('P1M')); } //ksort($monthsData); return $monthsData; } $monthsData = getMonths('2018-05-01', '2020-01-01' ); $grid = array(); foreach ($monthsData as $month) { $grid[$month]['montant'] = 0; } var_dump($grid[$month]);
based on Dakvb
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.1.0 - 7.3.0alpha1
array(1) { ["montant"]=> int(0) }