3v4l.org

run code in 300+ PHP versions simultaneously
<?php function roundTime($timestamp, $interval, $direction){ $rounded_seconds = 0; switch ($direction) { case "u": //round up $rounded_seconds = ceil($timestamp / ($interval * 60)) * ($interval * 60); break; case "d": //round down $rounded_seconds = floor($timestamp / ($interval * 60)) * ($interval * 60); break; default: echo "default"; } return date('H:i', $rounded_seconds) . "\n"; } $testTimes = [ "2023-05-30 14:05", "2023-05-30 14:23", "2023-05-30 14:35", "2023-05-30 14:40", "2023-05-30 14:55" ]; foreach ($testTimes as $time) { echo "base time: ".$time.PHP_EOL; echo "round up to 15 mins: ".roundTime(strtotime($time), 15, "u"); echo "round up to 30 mins: ".roundTime(strtotime($time), 30, "u"); echo "round down to 15 mins: ".roundTime(strtotime($time), 15, "d"); echo "round down to 30 mins: ".roundTime(strtotime($time), 30, "d"); echo PHP_EOL; }
Output for git.master_jit, git.master, rfc.property-hooks
base time: 2023-05-30 14:05 round up to 15 mins: 14:15 round up to 30 mins: 14:30 round down to 15 mins: 14:00 round down to 30 mins: 14:00 base time: 2023-05-30 14:23 round up to 15 mins: 14:30 round up to 30 mins: 14:30 round down to 15 mins: 14:15 round down to 30 mins: 14:00 base time: 2023-05-30 14:35 round up to 15 mins: 14:45 round up to 30 mins: 15:00 round down to 15 mins: 14:30 round down to 30 mins: 14:30 base time: 2023-05-30 14:40 round up to 15 mins: 14:45 round up to 30 mins: 15:00 round down to 15 mins: 14:30 round down to 30 mins: 14:30 base time: 2023-05-30 14:55 round up to 15 mins: 15:00 round up to 30 mins: 15:00 round down to 15 mins: 14:45 round down to 30 mins: 14:30

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:
46.09 ms | 1077 KiB | 4 Q