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");

preferences:
23.92 ms | 404 KiB | 5 Q