3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /** * Boilerplate to setup variables */ $start = new DateTime('2013-01-01'); $end = new DateTime('2013-12-31'); $interval = new DateInterval('P1D'); $period = new DatePeriod($start, $interval, $end->add($interval)); foreach($period as $date){ $dateArray[] = $date->format('Y-m-d'); } /** * End of boilerplate */ /** * Answer code */ $countArray = array('Jan' => 0, 'Feb' => 0, 'Mar' => 0, 'Apr' => 0, 'May' => 0, 'Jun' => 0, 'Jul' => 0, 'Aug' => 0, 'Sep' => 0, 'Oct' => 0, 'Nov' => 0, 'Dec' => 0); foreach($dateArray as $dateString){ $date = new DateTime($dateString); $countArray[$date->format('M')]++; } var_dump($countArray);
Output for 5.3.0 - 7.1.0
array(12) { ["Jan"]=> int(31) ["Feb"]=> int(28) ["Mar"]=> int(31) ["Apr"]=> int(30) ["May"]=> int(31) ["Jun"]=> int(30) ["Jul"]=> int(31) ["Aug"]=> int(31) ["Sep"]=> int(30) ["Oct"]=> int(31) ["Nov"]=> int(30) ["Dec"]=> int(31) }
Output for 5.2.0 - 5.2.17
Fatal error: Class 'DateInterval' not found in /in/2qIcN on line 7
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/2qIcN on line 5
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: datetime in /in/2qIcN on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: datetime in /in/2qIcN on line 5