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 = date_create("2018-10-25 00:00:00"); //mktime(0, 0, 0, 10, 25, 2018); $permit_active_date = date_create("2018-10-25 00:00:00"); $pay_frequency = "BW"; $UCDHS_MasterPaySchedule = array ( "BW" => array ( array ( "file_submit_date" => date_create("2018-09-14 00:00:00"), "pay_check_date" => date_create("2018-09-19 00:00:00"), "park_period_start" => date_create("2018-10-01 00:00:00"), "park_period_end" => date_create("2018-10-15 00:00:00"), "check_num" => 1 ), array ( "file_submit_date" => date_create("2018-09-28 00:00:00"), "pay_check_date" => date_create("2018-10-03 00:00:00"), "park_period_start" => date_create("2018-10-16 00:00:00"), "park_period_end" => date_create("2018-10-31 00:00:00"), "check_num" => 2 ), array ( "file_submit_date" => date_create("2018-10-12 00:00:00"), "pay_check_date" => date_create("2018-10-17 00:00:00"), "park_period_start" => date_create("2018-11-01 00:00:00"), "park_period_end" => date_create("2018-11-15 00:00:00"), "check_num" => 3 ), array ( "file_submit_date" => date_create("2018-11-08 00:00:00"), "pay_check_date" => date_create("2018-11-14 00:00:00"), "park_period_start" => date_create("2018-11-16 00:00:00"), "park_period_end" => date_create("2018-11-30 00:00:00"), "check_num" => 4 ), array ( "file_submit_date" => date_create("2018-11-21 00:00:00"), "pay_check_date" => date_create("2018-11-28 00:00:00"), "park_period_start" => date_create("2018-12-01 00:00:00"), "park_period_end" => date_create("2018-12-15 00:00:00"), "check_num" => 5 ), array ( "file_submit_date" => date_create("2018-12-07 00:00:00"), "pay_check_date" => date_create("2018-12-12 00:00:00"), "park_period_start" => date_create("2018-12-16 00:00:00"), "park_period_end" => date_create("2018-12-31 00:00:00"), "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, $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]; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VRmIu
function name:  (null)
number of ops:  129
compiled vars:  !0 = $current_date, !1 = $permit_active_date, !2 = $pay_frequency, !3 = $UCDHS_MasterPaySchedule, !4 = $pay_cycle_for_active_date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   INIT_FCALL                                               'date_create'
          1        SEND_VAL                                                 '2018-10-25+00%3A00%3A00'
          2        DO_ICALL                                         $5      
          3        ASSIGN                                                   !0, $5
    8     4        INIT_FCALL                                               'date_create'
          5        SEND_VAL                                                 '2018-10-25+00%3A00%3A00'
          6        DO_ICALL                                         $7      
          7        ASSIGN                                                   !1, $7
    9     8        ASSIGN                                                   !2, 'BW'
   14     9        INIT_FCALL                                               'date_create'
         10        SEND_VAL                                                 '2018-09-14+00%3A00%3A00'
         11        DO_ICALL                                         $10     
         12        INIT_ARRAY                                       ~11     $10, 'file_submit_date'
   15    13        INIT_FCALL                                               'date_create'
         14        SEND_VAL                                                 '2018-09-19+00%3A00%3A00'
         15        DO_ICALL                                         $12     
         16        ADD_ARRAY_ELEMENT                                ~11     $12, 'pay_check_date'
   16    17        INIT_FCALL                                               'date_create'
         18        SEND_VAL                                                 '2018-10-01+00%3A00%3A00'
         19        DO_ICALL                                         $13     
         20        ADD_ARRAY_ELEMENT                                ~11     $13, 'park_period_start'
   17    21        INIT_FCALL                                               'date_create'
         22        SEND_VAL                                                 '2018-10-15+00%3A00%3A00'
         23        DO_ICALL                                         $14     
         24        ADD_ARRAY_ELEMENT                                ~11     $14, 'park_period_end'
   18    25        ADD_ARRAY_ELEMENT                                ~11     1, 'check_num'
         26        INIT_ARRAY                                       ~15     ~11
   21    27        INIT_FCALL                                               'date_create'
         28        SEND_VAL                                                 '2018-09-28+00%3A00%3A00'
         29        DO_ICALL                                         $16     
         30        INIT_ARRAY                                       ~17     $16, 'file_submit_date'
   22    31        INIT_FCALL                                               'date_create'
         32        SEND_VAL                                                 '2018-10-03+00%3A00%3A00'
         33        DO_ICALL                                         $18     
         34        ADD_ARRAY_ELEMENT                                ~17     $18, 'pay_check_date'
   23    35        INIT_FCALL                                               'date_create'
         36        SEND_VAL                                                 '2018-10-16+00%3A00%3A00'
         37        DO_ICALL                                         $19     
         38        ADD_ARRAY_ELEMENT                                ~17     $19, 'park_period_start'
   24    39        INIT_FCALL                                               'date_create'
         40        SEND_VAL                                                 '2018-10-31+00%3A00%3A00'
         41        DO_ICALL                                         $20     
         42        ADD_ARRAY_ELEMENT                                ~17     $20, 'park_period_end'
   25    43        ADD_ARRAY_ELEMENT                                ~17     2, 'check_num'
         44        ADD_ARRAY_ELEMENT                                ~15     ~17
   28    45        INIT_FCALL                                               'date_create'
         46        SEND_VAL                                                 '2018-10-12+00%3A00%3A00'
         47        DO_ICALL                                         $21     
         48        INIT_ARRAY                                       ~22     $21, 'file_submit_date'
   29    49        INIT_FCALL                                               'date_create'
         50        SEND_VAL                                                 '2018-10-17+00%3A00%3A00'
         51        DO_ICALL                                         $23     
         52        ADD_ARRAY_ELEMENT                                ~22     $23, 'pay_check_date'
   30    53        INIT_FCALL                                               'date_create'
         54        SEND_VAL                                                 '2018-11-01+00%3A00%3A00'
         55        DO_ICALL                                         $24     
         56        ADD_ARRAY_ELEMENT                                ~22     $24, 'park_period_start'
   31    57        INIT_FCALL                                               'date_create'
         58        SEND_VAL                                                 '2018-11-15+00%3A00%3A00'
         59        DO_ICALL                                         $25     
         60        ADD_ARRAY_ELEMENT                                ~22     $25, 'park_period_end'
   32    61        ADD_ARRAY_ELEMENT                                ~22     3, 'check_num'
         62        ADD_ARRAY_ELEMENT                                ~15     ~22
   35    63        INIT_FCALL                                               'date_create'
         64        SEND_VAL                                                 '2018-11-08+00%3A00%3A00'
         65        DO_ICALL                                         $26     
         66        INIT_ARRAY                                       ~27     $26, 'file_submit_date'
   36    67        INIT_FCALL                                               'date_create'
         68        SEND_VAL                                                 '2018-11-14+00%3A00%3A00'
         69        DO_ICALL                                         $28     
         70        ADD_ARRAY_ELEMENT                                ~27     $28, 'pay_check_date'
   37    71        INIT_FCALL                                               'date_create'
         72        SEND_VAL                                                 '2018-11-16+00%3A00%3A00'
         73        DO_ICALL                                         $29     
         74        ADD_ARRAY_ELEMENT                                ~27     $29, 'park_period_start'
   38    75        INIT_FCALL                                               'date_create'
         76        SEND_VAL                                                 '2018-11-30+00%3A00%3A00'
         77        DO_ICALL                                         $30     
         78        ADD_ARRAY_ELEMENT                                ~27     $30, 'park_period_end'
   39    79        ADD_ARRAY_ELEMENT                                ~27     4, 'check_num'
         80        ADD_ARRAY_ELEMENT                                ~15     ~27
   42    81        INIT_FCALL                                               'date_create'
         82        SEND_VAL                                                 '2018-11-21+00%3A00%3A00'
         83        DO_ICALL                                         $31     
         84        INIT_ARRAY                                       ~32     $31, 'file_submit_date'
   43    85        INIT_FCALL                                               'date_create'
         86        SEND_VAL                                                 '2018-11-28+00%3A00%3A00'
         87        DO_ICALL                                         $33     
         88        ADD_ARRAY_ELEMENT                                ~32     $33, 'pay_check_date'
   44    89        INIT_FCALL                                               'date_create'
         90        SEND_VAL                                                 '2018-12-01+00%3A00%3A00'
         91        DO_ICALL                                         $34     
         92        ADD_ARRAY_ELEMENT                                ~32     $34, 'park_period_start'
   45    93        INIT_FCALL                                               'date_create'
         94        SEND_VAL                                                 '2018-12-15+00%3A00%3A00'
         95        DO_ICALL                                         $35     
         96        ADD_ARRAY_ELEMENT                                ~32     $35, 'park_period_end'
   46    97        ADD_ARRAY_ELEMENT                                ~32     5, 'check_num'
         98        ADD_ARRAY_ELEMENT                                ~15     ~32
   49    99        INIT_FCALL                                               'date_create'
        100        SEND_VAL                                                 '2018-12-07+00%3A00%3A00'
        101        DO_ICALL                                         $36     
        102        INIT_ARRAY                                       ~37     $36, 'file_submit_date'
   50   103        INIT_FCALL                                               'date_create'
        104        SEND_VAL                                                 '2018-12-12+00%3A00%3A00'
        105        DO_ICALL                                         $38     
        106        ADD_ARRAY_ELEMENT                                ~37     $38, 'pay_check_date'
   51   107        INIT_FCALL                                               'date_create'
        108        SEND_VAL                                                 '2018-12-16+00%3A00%3A00'
        109        DO_ICALL                                         $39     
        110        ADD_ARRAY_ELEMENT                                ~37     $39, 'park_period_start'
   52   111        INIT_FCALL                                               'date_create'
        112        SEND_VAL                                                 '2018-12-31+00%3A00%3A00'
        113        DO_ICALL                                         $40     
        114        ADD_ARRAY_ELEMENT                                ~37     $40, 'park_period_end'
   53   115        ADD_ARRAY_ELEMENT                                ~37     6, 'check_num'
        116        ADD_ARRAY_ELEMENT                                ~15     ~37
        117        INIT_ARRAY                                       ~41     ~15, 'BW'
   11   118        ASSIGN                                                   !3, ~41
   62   119        INIT_FCALL_BY_NAME                                       'get_pay_cycle_for_active_date'
        120        SEND_VAR_EX                                              !0
        121        SEND_VAR_EX                                              !1
        122        CHECK_FUNC_ARG                                           
        123        FETCH_DIM_FUNC_ARG                               $43     !3, !2
        124        SEND_FUNC_ARG                                            $43
        125        DO_FCALL                                      0  $44     
        126        ASSIGN                                                   !4, $44
   63   127        ECHO                                                     !4
  147   128      > RETURN                                                   1

Function daysbetween:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VRmIu
function name:  daysBetween
number of ops:  11
compiled vars:  !0 = $dt1, !1 = $dt2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   77     2        INIT_FCALL                                               'date_diff'
   78     3        SEND_VAR                                                 !1
   79     4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
   80     6        INIT_METHOD_CALL                                         $2, 'format'
          7        SEND_VAL_EX                                              '%25a'
          8        DO_FCALL                                      0  $3      
          9      > RETURN                                                   $3
   81    10*     > RETURN                                                   null

End of function daysbetween

Function get_pay_cycle_for_active_date:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 31
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 31
Branch analysis from position: 7
2 jumps found. (Code = 46) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
2 jumps found. (Code = 46) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 24
Branch analysis from position: 22
Branch analysis from position: 16
Branch analysis from position: 14
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/VRmIu
function name:  get_pay_cycle_for_active_date
number of ops:  50
compiled vars:  !0 = $current_date, !1 = $permit_active_date, !2 = $arr_pay_schedule, !3 = $current_period_id, !4 = $active_period_id, !5 = $period, !6 = $period_num, !7 = $days_valid_in_active_period
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   83     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   87     3        ASSIGN                                                   !3, -1
   88     4        ASSIGN                                                   !4, -1
   96     5      > FE_RESET_R                                       $10     !2, ->31
          6    > > FE_FETCH_R                                       ~11     $10, !5, ->31
          7    >   ASSIGN                                                   !6, ~11
   99     8        FETCH_DIM_R                                      ~13     !5, 'park_period_start'
          9        IS_SMALLER_OR_EQUAL                              ~14     ~13, !0
         10      > JMPZ_EX                                          ~14     ~14, ->14
         11    >   FETCH_DIM_R                                      ~15     !5, 'park_period_end'
         12        IS_SMALLER_OR_EQUAL                              ~16     !0, ~15
         13        BOOL                                             ~14     ~16
         14    > > JMPZ                                                     ~14, ->16
  100    15    >   ASSIGN                                                   !3, !6
  104    16    >   FETCH_DIM_R                                      ~18     !5, 'park_period_start'
         17        IS_SMALLER_OR_EQUAL                              ~19     ~18, !1
         18      > JMPZ_EX                                          ~19     ~19, ->22
         19    >   FETCH_DIM_R                                      ~20     !5, 'park_period_end'
         20        IS_SMALLER_OR_EQUAL                              ~21     !1, ~20
         21        BOOL                                             ~19     ~21
         22    > > JMPZ                                                     ~19, ->24
  105    23    >   ASSIGN                                                   !4, !6
  109    24    >   INIT_FCALL                                               'daysbetween'
         25        SEND_VAR                                                 !1
         26        FETCH_DIM_R                                      ~23     !5, 'park_period_end'
         27        SEND_VAL                                                 ~23
         28        DO_FCALL                                      0  $24     
         29        ASSIGN                                                   !7, $24
   96    30      > JMP                                                      ->6
         31    >   FE_FREE                                                  $10
  112    32        CONCAT                                           ~26     'current_period_id+%3D+', !3
         33        CONCAT                                           ~27     ~26, '%0C%0D'
         34        ECHO                                                     ~27
  113    35        CONCAT                                           ~28     'active_period_id+%3D+', !4
         36        CONCAT                                           ~29     ~28, '%0C%0D'
         37        ECHO                                                     ~29
  114    38        CONCAT                                           ~30     'days_valid_in_active_period+%3D+', !7
         39        CONCAT                                           ~31     ~30, '%0C%0D'
         40        ECHO                                                     ~31
  115    41        CONCAT                                           ~32     'permit_active_date+%3D+', !1
         42        CONCAT                                           ~33     ~32, '%0C%0D'
         43        ECHO                                                     ~33
  116    44        FETCH_DIM_R                                      ~34     !5, 'park_period_end'
         45        CONCAT                                           ~35     'period%5B%27park_period_end%27%5D+%3D+', ~34
         46        CONCAT                                           ~36     ~35, '%0C%0D'
         47        ECHO                                                     ~36
  117    48      > RETURN                                                   ''
  125    49*     > RETURN                                                   null

End of function get_pay_cycle_for_active_date

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.79 ms | 1415 KiB | 18 Q