3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function ISOdates_from_weeknr ($weeknr, $year, $format = '%d-%m-%Y') { $start = strtotime ('1 january ' . $year); $week1 = strftime ('%V', $start); while ($week1 != '01') { $start += (7 * 24 * 3600); $week1 = strftime ('%V', $start); } $timestamp_week = strtotime ('+' . ($weeknr - 1) . ' week', $start); $weekdag = strftime ('%u', $timestamp_week); $dagen_tot_begin_week = $weekdag - 1; $dagen_tot_eind_week = 7 - $weekdag; $checkdatum = strtotime ("-" . $dagen_tot_begin_week . " days + 3 days", $timestamp_week); $check = strftime ('%V', $checkdatum); if ($check == '01' && $weeknr > 52) { echo 'ongeldig weeknummer voor dit jaar' . "\n"; return false; } $begindatum = strtotime ("-" . $dagen_tot_begin_week . " days", $timestamp_week); $einddatum = strtotime ("+" . $dagen_tot_eind_week . " days", $timestamp_week); return array (strftime ($format, $begindatum), strftime ($format, $einddatum)); } echo "Output for 5.4.11 - 7.0.2, 7.1@2015-11, hhvm-3.6.1 - 3.11.0".PHP_EOL; echo ISOdates_from_weeknr(1, 2016)[0].PHP_EOL; echo ISOdates_from_weeknr(1, 2016)[1]; echo "Andere PHP die oud is".PHP_EOL; $date = ISOdates_from_weeknr(1, 2016); echo $date[0].PHP_EOL; echo $date[1].PHP_EOL; ?>
based on MThdS
Output for 5.4.11 - 7.2.0
Output for 5.4.11 - 7.0.2, 7.1@2015-11, hhvm-3.6.1 - 3.11.0 04-01-2016 10-01-2016Andere PHP die oud is 04-01-2016 10-01-2016
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ',' or ';' in /in/e7hH4 on line 24
Process exited with code 255.