3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start_date = '2019-01-01'; $end_date = '2019-12-31'; function makeBroadcastCalendar($start_date, $end_date) { $end = new DateTime($end_date); $start = new DateTime($start_date); $start->modify('monday this week'); $week = 1; $weeks = array(); while($start < $end) { $weeks[$week++] = $start->format('Y-m-d'); $start->modify('+1 week'); } return $weeks; } function getBroadcastMonth($date) { $end_of_week = new DateTime($date); $end_of_week->modify('sunday this week'); return (int)$end_of_week->format('n'); } function getBroadcastWeek($date) { $start = new DateTime($date); $start->modify('January 1'); $start->modify('monday this week'); $start_of_week = new DateTime($date); $start_of_week->modify('monday this week'); $week = 1; while ($start < $start_of_week) { $start->modify('+1 week'); $week++; } return $week; } function getFirstAndLast($year, $month) { $start = new DateTime("$year-$month-01"); $end = clone $start; $start->modify('monday this week'); $output = array('first_day' => $start->format('Y-m-d')); $end->modify('+1 month'); $end->modify('monday this week'); while ($start < $end) { $start->modify('+1 week'); } $output['end'] = $start->modify('-1 day')->format('Y-m-d'); return $output; } echo getBroadcastMonth('2019-10-12') . PHP_EOL; echo getBroadcastMonth('2019-10-29') . PHP_EOL; echo getBroadcastMonth('2019-05-31') . PHP_EOL; echo getBroadcastWeek('2019-10-12') . PHP_EOL; echo getBroadcastWeek('2019-10-29') . PHP_EOL; echo getBroadcastWeek('2019-05-31') . PHP_EOL; for ($i = 1; $i <= 12; $i++) { print_r(getFirstAndLast(2019, $i)); }
Output for git.master, git.master_jit, rfc.property-hooks
10 11 6 41 44 22 Array ( [first_day] => 2018-12-31 [end] => 2019-01-27 ) Array ( [first_day] => 2019-01-28 [end] => 2019-02-24 ) Array ( [first_day] => 2019-02-25 [end] => 2019-03-31 ) Array ( [first_day] => 2019-04-01 [end] => 2019-04-28 ) Array ( [first_day] => 2019-04-29 [end] => 2019-05-26 ) Array ( [first_day] => 2019-05-27 [end] => 2019-06-30 ) Array ( [first_day] => 2019-07-01 [end] => 2019-07-28 ) Array ( [first_day] => 2019-07-29 [end] => 2019-08-25 ) Array ( [first_day] => 2019-08-26 [end] => 2019-09-29 ) Array ( [first_day] => 2019-09-30 [end] => 2019-10-27 ) Array ( [first_day] => 2019-10-28 [end] => 2019-11-24 ) Array ( [first_day] => 2019-11-25 [end] => 2019-12-29 )

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:
132.69 ms | 407 KiB | 5 Q