3v4l.org

run code in 300+ PHP versions simultaneously
<?php $date = new DateTime("first day of next month"); $publicHolidays = ['01-01', '05-01']; // Format: mm-dd while (true) { // format("N") >= 6 == Weekend if ($date->format("N") >= 6) { // If Saturday or Sunday, add 1 or 2 days. // N=6 (Saturday), 8-6 = 2, get monday // N=7 (Sunday), 8-7 = 1, get monday $date->modify("+".(8-$date->format("N"))." days"); } elseif (in_array($date->format("m-d"), $publicHolidays)) { // This day is a public holiday! Add one. $date->modify("+1 day"); } else { break; } } echo $date->format("Y-m-d");
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
2022-12-01

preferences:
122.12 ms | 407 KiB | 5 Q