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'); return date_diff( $dt2, mktime(0, 0, 0, 10, 25, 2018) )->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 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Fatal error: Uncaught TypeError: date_diff(): Argument #1 ($baseObject) must be of type DateTimeInterface, int given in /in/oAH9F:76 Stack trace: #0 /in/oAH9F(76): date_diff(1539554400, 1540418400) #1 /in/oAH9F(108): daysBetween(1540418400, 1539554400) #2 /in/oAH9F(61): get_pay_cycle_for_active_date(1540418400, 1540418400, Array) #3 {main} thrown in /in/oAH9F on line 76
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Uncaught TypeError: date_diff(): Argument #1 ($baseObject) must be of type DateTimeInterface, int given in /in/oAH9F:76 Stack trace: #0 /in/oAH9F(76): date_diff(1539554400, 1540418400) #1 /in/oAH9F(108): daysBetween(1540418400, 1539554400) #2 /in/oAH9F(61): get_pay_cycle_for_active_date(1540418400, 1540418400, Array) #3 {main} thrown in /in/oAH9F on line 76
Process exited with code 255.
Output for 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28
Fatal error: Uncaught TypeError: date_diff(): Argument #1 ($baseObject) must be of type DateTimeInterface, int given in /in/oAH9F:78 Stack trace: #0 /in/oAH9F(78): date_diff(1539554400, 1540418400) #1 /in/oAH9F(108): daysBetween(1540418400, 1539554400) #2 /in/oAH9F(61): get_pay_cycle_for_active_date(1540418400, 1540418400, Array) #3 {main} thrown in /in/oAH9F on line 78
Process exited with code 255.
Output for 8.0.13
Fatal error: Uncaught TypeError: date_diff(): Argument #1 ($baseObject) must be of type DateTimeInterface, int given in /in/oAH9F:78 Stack trace: #0 /in/oAH9F(78): date_diff(1539561600, 1540425600) #1 /in/oAH9F(108): daysBetween(1540425600, 1539561600) #2 /in/oAH9F(61): get_pay_cycle_for_active_date(1540425600, 1540425600, Array) #3 {main} thrown in /in/oAH9F on line 78
Process exited with code 255.
Output for 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
Warning: date_diff() expects parameter 1 to be DateTimeInterface, int given in /in/oAH9F on line 78 Fatal error: Uncaught Error: Call to a member function format() on bool in /in/oAH9F:79 Stack trace: #0 /in/oAH9F(108): daysBetween(1540418400, 1539554400) #1 /in/oAH9F(61): get_pay_cycle_for_active_date(1540418400, 1540418400, Array) #2 {main} thrown in /in/oAH9F on line 79
Process exited with code 255.
Output for 7.3.32 - 7.3.33
Warning: date_diff() expects parameter 1 to be DateTimeInterface, int given in /in/oAH9F on line 78 Fatal error: Uncaught Error: Call to a member function format() on bool in /in/oAH9F:79 Stack trace: #0 /in/oAH9F(108): daysBetween(1540425600, 1539561600) #1 /in/oAH9F(61): get_pay_cycle_for_active_date(1540425600, 1540425600, Array) #2 {main} thrown in /in/oAH9F on line 79
Process exited with code 255.
Output for 7.1.0 - 7.1.23, 7.2.0 - 7.2.33
Warning: date_diff() expects parameter 1 to be DateTimeInterface, integer given in /in/oAH9F on line 78 Fatal error: Uncaught Error: Call to a member function format() on boolean in /in/oAH9F:79 Stack trace: #0 /in/oAH9F(108): daysBetween(1540418400, 1539554400) #1 /in/oAH9F(61): get_pay_cycle_for_active_date(1540418400, 1540418400, Array) #2 {main} thrown in /in/oAH9F on line 79
Process exited with code 255.
Output for 5.6.38
Warning: date_diff() expects parameter 1 to be DateTimeInterface, integer given in /in/oAH9F on line 79 Fatal error: Call to a member function format() on boolean in /in/oAH9F on line 79
Process exited with code 255.

preferences:
157.91 ms | 401 KiB | 173 Q