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 = ['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.4.0 - 5.6.28, hhvm-3.10.0 - 3.13.2, 7.0.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.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/iaAq1 on line 20
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/iaAq1 on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/iaAq1 on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/iaAq1 on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/iaAq1 on line 8 Parse error: syntax error, unexpected '[' in /in/iaAq1 on line 20
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/iaAq1 on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/iaAq1 on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/iaAq1 on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/iaAq1 on line 8 Parse error: parse error, unexpected '[' in /in/iaAq1 on line 20
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/iaAq1 on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/iaAq1 on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/iaAq1 on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/iaAq1 on line 8 Parse error: parse error in /in/iaAq1 on line 20
Process exited with code 255.