3v4l.org

run code in 300+ PHP versions simultaneously
<?php //$current_date = mktime(0, 0, 0, date("m"), date("d"), date("Y")); //$permit_active_date = mktime(0, 0, 0, date("m"), date("d"), date("Y")); $current_date = mktime(0, 0, 0, 10, 25, 2018); $permit_active_date = mktime(0, 0, 0, 10, 25, 2018); $pay_frequency = "BW"; $UCDHS_MasterPaySchedule = array ( "BW" => array ( array ( "file_submit_date" => mktime(0,0,0,9,14,2018), "pay_check_date" => mktime(0,0,0,9,19,2018), "park_period_start" => mktime(0,0,0,10,1,2018), "park_period_end" => mktime(0,0,0,10,15,2018), "check_num" => 1 ), array ( "file_submit_date" => mktime(0,0,0,9,28,2018), "pay_check_date" => mktime(0,0,0,10,3,2018), "park_period_start" => mktime(0,0,0,10,16,2018), "park_period_end" => mktime(0,0,0,10,31,2018), "check_num" => 2 ), array ( "file_submit_date" => mktime(0,0,0,10,12,2018), "pay_check_date" => mktime(0,0,0,10,17,2018), "park_period_start" => mktime(0,0,0,11,1,2018), "park_period_end" => mktime(0,0,0,11,15,2018), "check_num" => 3 ), array ( "file_submit_date" => mktime(0,0,0,11,8,2018), "pay_check_date" => mktime(0,0,0,11,14,2018), "park_period_start" => mktime(0,0,0,11,16,2018), "park_period_end" => mktime(0,0,0,11,30,2018), "check_num" => 4 ), array ( "file_submit_date" => mktime(0,0,0,11,21,2018), "pay_check_date" => mktime(0,0,0,11,28,2018), "park_period_start" => mktime(0,0,0,12,1,2018), "park_period_end" => mktime(0,0,0,12,15,2018), "check_num" => 5 ), array ( "file_submit_date" => mktime(0,0,0,12,7,2018), "pay_check_date" => mktime(0,0,0,12,12,2018), "park_period_start" => mktime(0,0,0,12,16,2018), "park_period_end" => mktime(0,0,0,12,31,2018), "check_num" => 6 ) ) ); //reduce array to pay schedule // $arrPaySchedule = $UCDHS_MasterPaySchedule[$pay_frequency]; //find pay cycle where parking period includes permit start date $pay_cycle_for_active_date = get_pay_cycle_for_active_date($current_date, $permit_active_date, $UCDHS_MasterPaySchedule[$pay_frequency]); print $pay_cycle_for_active_date; /** * Number of days between two dates. * * @param date $dt1 First date * @param date $dt2 Second date * @return int */ function daysBetween($dt1, $dt2) { return date_diff( date_create($dt2), date_create($dt1) )->format('%a'); } function get_pay_cycle_for_active_date($current_date, $permit_active_date, $arr_pay_schedule) { // note: function assumes that pay period data is ordered earliest to latest, in the arrPaySchedule array //default values: $current_period_id = -1; $active_period_id = -1; //$return_file_submit_date //pay_check_date //park_period_start //park_period_end //check_num //loop through pay periods... foreach($arr_pay_schedule as $period_num => $period) { //find current parking period if ($current_date >= $period["park_period_start"] && $current_date <= $period["park_period_end"]) { $current_period_id = $period_num; } //find parking period which contains permit_active_date if ($permit_active_date >= $period["park_period_start"] && $permit_active_date <= $period["park_period_end"]) { $active_period_id = $period_num; } //determine number of days permit is valid in perid permit becomes valid $days_valid_in_active_period = daysBetween($permit_active_date, $period["park_period_end"]); } echo "current_period_id = ".$current_period_id."\f\r"; echo "active_period_id = ".$active_period_id."\f\r"; echo "days_valid_in_active_period = ".$days_valid_in_active_period."\f\r"; echo "permit_active_date = ".$permit_active_date."\f\r"; echo "period['park_period_end'] = ".$period["park_period_end"]."\f\r"; return ""; // $arrSelectedSchedule = array_filter($arrPaySchedule, function($e) use($permit_active_date) {return ($e["park_period_start"]<=$permit_active_date && $e["park_period_end"]>=$permit_active_date);}); // print_r($arrSelectedSchedule); // return array_search() // return count(array_filter($arrPaySchedule, function($e) use($permit_active_date) {return ($e["park_period_start"]<=$permit_active_date && $e["park_period_end"]>=$permit_active_date);})); } //$min=mktime(0,0,0,10,1,2018); //$max=mktime(0,0,0,10,4,2018); //print count(array_filter($UCDHSPaySchedule["BW"], function($e) use($min,$max) {return ($e["permit_active_date"]>$min && $e["permit_active_date"]<$max);})); //function gets the number of submittion dates between the $current_date and the submission date for permit starting on $active_date //function get_cycle_count($current_date, $active_date, $UCDHSPaySchedule) { //print count(array_filter($UCDHSPaySchedule["BW"], function($e) use($min,$max) {return ($e["permit_active_date"]>$min && //$e["permit_active_date"]<$max);})); //} //$cars = array ( //"Volvo" => array("Volvo",22,18), //"BMW" => array("BMW",15,13), //"Saab" => array("Saab",5,2), //"Land Rover" => array("Land Rover",17,15) //); //print $cars['Volvo'][0]; ?>
Output for git.master, git.master_jit
Fatal error: Uncaught TypeError: date_diff(): Argument #1 ($baseObject) must be of type DateTimeInterface, bool given in /in/aQYv7:72 Stack trace: #0 /in/aQYv7(72): date_diff(false, Object(DateTime)) #1 /in/aQYv7(104): daysBetween(1540418400, 1540940400) #2 /in/aQYv7(61): get_pay_cycle_for_active_date(1540418400, 1540418400, Array) #3 {main} thrown in /in/aQYv7 on line 72
Process exited with code 255.
Output for rfc.property-hooks
Fatal error: Uncaught TypeError: date_diff(): Argument #1 ($baseObject) must be of type DateTimeInterface, false given in /in/aQYv7:72 Stack trace: #0 /in/aQYv7(72): date_diff(false, Object(DateTime)) #1 /in/aQYv7(104): daysBetween(1540418400, 1540940400) #2 /in/aQYv7(61): get_pay_cycle_for_active_date(1540418400, 1540418400, Array) #3 {main} thrown in /in/aQYv7 on line 72
Process exited with code 255.

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