3v4l.org

run code in 500+ PHP versions simultaneously
<?php $tests = [ '2016-01','2016-02','2016-03','2016-04','2016-05','2016-06','2016-07','2016-08','2016-09','2016-10','2016-11','2016-12', '2018-01','2018-02','2018-03','2018-04','2018-05','2018-06','2018-07','2018-08','2018-09','2018-10','2018-11','2018-12', ]; foreach($tests as $test) { $start = new DateTime($test); $end = intval((clone $start)->modify('last day of this month')->format('W')); if($end < 2) $end = intval((clone $start)->modify('last sunday of this month')->format('W')) + 1; $start = intval($start->format('W')); if($start > 51) $start = 0;$weeks = $end - $start + 1; echo "$test = $weeks\n"; }
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.21, 8.5.0 - 8.5.6
2016-01 = 5 2016-02 = 5 2016-03 = 5 2016-04 = 5 2016-05 = 6 2016-06 = 5 2016-07 = 5 2016-08 = 5 2016-09 = 5 2016-10 = 6 2016-11 = 5 2016-12 = 5 2018-01 = 5 2018-02 = 5 2018-03 = 5 2018-04 = 6 2018-05 = 5 2018-06 = 5 2018-07 = 6 2018-08 = 5 2018-09 = 5 2018-10 = 5 2018-11 = 5 2018-12 = 6
Output for 5.6.0 - 5.6.40
Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in /in/WoAiN on line 9
Process exited with code 255.

preferences:
101.36 ms | 2046 KiB | 4 Q