3v4l.org

run code in 300+ PHP versions simultaneously
<?php $year = 2013; $month = 10; $week_nr_of_month = 3; // from 1 to 6 weeks in month $day_of_week = 0; // Sunday date("w") $start = new DateTime(); $start->setDate($year, $month, '1'); $end = clone $start; $end->modify('last day of month'); $interval = new DateInterval('P1D'); $period = new DatePeriod($start, $interval, $end); $week = 0; foreach ($period as $date) { if ($date->format('w') === $day_of_week) { $week++; if ($week_nr_of_month === $week) { // bingo! } } }
Output for git.master, git.master_jit
Warning: DateTime::modify(): Failed to parse time string (last day of month) at position 12 (m): The timezone could not be found in the database in /in/eKD2n on line 11
Output for rfc.property-hooks
Fatal error: Uncaught DateMalformedStringException: DateTime::modify(): Failed to parse time string (last day of month) at position 12 (m): The timezone could not be found in the database in /in/eKD2n:11 Stack trace: #0 /in/eKD2n(11): DateTime->modify('last day of mon...') #1 {main} thrown in /in/eKD2n on line 11
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
50.69 ms | 401 KiB | 8 Q