3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tz = new DateTimeZone("UTC"); //lets say he chosed the service on Monday and Tuesday and Wednesday $days = "Monday ,Tuesday, Wednesday";// <-- change to user input $planDays = translateWeekDaysToNumbers($days); $planName = "Weekly";// <- change as user input if($planName == 'Weekly'){ $weekOrMonth = "week"; } else if ($planName == 'Monthly'){ $weekOrMonth = "month"; } else { //TODO: throw error } $startString = "2019-02-01 00:00:00"; // <- change later to "now" $startDate = new DateTime($startString, $tz); $afterMonth = new DateTime("@" . strtotime("+1 $weekOrMonth", $startDate->format("U"))); $numberOfDays = $afterMonth->diff($startDate)->days; $daysOfService = 0; // what we need to calculate for($i = 0; $i<$numberOfDays; $i++){ $dateInterval = new DateInterval("P{$i}D"); $startDate->add($dateInterval); if (in_array($startDate->format("w"), $planDays)) $daysOfService ++; $startDate->sub($dateInterval);//reset to first day } $pro_price = 100;// <--- change to your price from the DB $totalPrice = $daysOfService * $pro_price; echo $daysOfService . "\n"; echo $totalPrice . "\n"; exit; function translateWeekDaysToNumbers(string $days) { //dont change the numbers as they are the given by ->format("w") $daysNumbers = [ "sunday" => 0, "monday" => 1, "tuesday" => 2, "wednesday" => 3, "thursday" => 4, "friday" => 5, "saturday" => 6 ]; $days = explode(",", $days); $planDays = []; foreach($days as $day){ $day = strtolower(trim($day)); if (isset($daysNumbers[$day])) $planDays[] = $daysNumbers[$day]; } return $planDays; }
Output for git.master_jit, git.master
/bin/php-git-master: error while loading shared libraries: libonig.so.5: cannot open shared object file: No such file or directory
Process exited with code 127.
Output for rfc.property-hooks
3 300

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:
56.71 ms | 401 KiB | 8 Q