3v4l.org

run code in 300+ PHP versions simultaneously
<?php $order_date = '2020-07-09 10:23:00'; // if no argument the, use the current time function getPossibleShippingDates($order_date = 'now', $num_day = 3) { $dates = []; $dt = new DateTime($order_date); if ($dt->format('H') >= 10) { // if ordered on or after 10, move to next day $dt->modify('+1 day'); } if (in_array($dt->format('N'), [6, 7])) { // if ordered weekend, adjust to start monday $dt->modify('next monday'); } $i = 1; while ($i <= $num_day) { if (!in_array($dt->format('N'), [6, 7])) { $dates[$i++] = $dt->format('Y-m-d'); } $dt->modify('+1 day'); } return $dates; } $dates = getPossibleShippingDates($order_date); print_r($dates);

preferences:
30.32 ms | 405 KiB | 5 Q