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]; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aQYv7
function name:  (null)
number of ops:  259
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                                               'mktime'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 0
          3        SEND_VAL                                                 0
          4        SEND_VAL                                                 10
          5        SEND_VAL                                                 25
          6        SEND_VAL                                                 2018
          7        DO_ICALL                                         $5      
          8        ASSIGN                                                   !0, $5
    7     9        INIT_FCALL                                               'mktime'
         10        SEND_VAL                                                 0
         11        SEND_VAL                                                 0
         12        SEND_VAL                                                 0
         13        SEND_VAL                                                 10
         14        SEND_VAL                                                 25
         15        SEND_VAL                                                 2018
         16        DO_ICALL                                         $7      
         17        ASSIGN                                                   !1, $7
    8    18        ASSIGN                                                   !2, 'BW'
   13    19        INIT_FCALL                                               'mktime'
         20        SEND_VAL                                                 0
         21        SEND_VAL                                                 0
         22        SEND_VAL                                                 0
         23        SEND_VAL                                                 9
         24        SEND_VAL                                                 14
         25        SEND_VAL                                                 2018
         26        DO_ICALL                                         $10     
         27        INIT_ARRAY                                       ~11     $10, 'file_submit_date'
   14    28        INIT_FCALL                                               'mktime'
         29        SEND_VAL                                                 0
         30        SEND_VAL                                                 0
         31        SEND_VAL                                                 0
         32        SEND_VAL                                                 9
         33        SEND_VAL                                                 19
         34        SEND_VAL                                                 2018
         35        DO_ICALL                                         $12     
         36        ADD_ARRAY_ELEMENT                                ~11     $12, 'pay_check_date'
   15    37        INIT_FCALL                                               'mktime'
         38        SEND_VAL                                                 0
         39        SEND_VAL                                                 0
         40        SEND_VAL                                                 0
         41        SEND_VAL                                                 10
         42        SEND_VAL                                                 1
         43        SEND_VAL                                                 2018
         44        DO_ICALL                                         $13     
         45        ADD_ARRAY_ELEMENT                                ~11     $13, 'park_period_start'
   16    46        INIT_FCALL                                               'mktime'
         47        SEND_VAL                                                 0
         48        SEND_VAL                                                 0
         49        SEND_VAL                                                 0
         50        SEND_VAL                                                 10
         51        SEND_VAL                                                 15
         52        SEND_VAL                                                 2018
         53        DO_ICALL                                         $14     
         54        ADD_ARRAY_ELEMENT                                ~11     $14, 'park_period_end'
   17    55        ADD_ARRAY_ELEMENT                                ~11     1, 'check_num'
         56        INIT_ARRAY                                       ~15     ~11
   20    57        INIT_FCALL                                               'mktime'
         58        SEND_VAL                                                 0
         59        SEND_VAL                                                 0
         60        SEND_VAL                                                 0
         61        SEND_VAL                                                 9
         62        SEND_VAL                                                 28
         63        SEND_VAL                                                 2018
         64        DO_ICALL                                         $16     
         65        INIT_ARRAY                                       ~17     $16, 'file_submit_date'
   21    66        INIT_FCALL                                               'mktime'
         67        SEND_VAL                                                 0
         68        SEND_VAL                                                 0
         69        SEND_VAL                                                 0
         70        SEND_VAL                                                 10
         71        SEND_VAL                                                 3
         72        SEND_VAL                                                 2018
         73        DO_ICALL                                         $18     
         74        ADD_ARRAY_ELEMENT                                ~17     $18, 'pay_check_date'
   22    75        INIT_FCALL                                               'mktime'
         76        SEND_VAL                                                 0
         77        SEND_VAL                                                 0
         78        SEND_VAL                                                 0
         79        SEND_VAL                                                 10
         80        SEND_VAL                                                 16
         81        SEND_VAL                                                 2018
         82        DO_ICALL                                         $19     
         83        ADD_ARRAY_ELEMENT                                ~17     $19, 'park_period_start'
   23    84        INIT_FCALL                                               'mktime'
         85        SEND_VAL                                                 0
         86        SEND_VAL                                                 0
         87        SEND_VAL                                                 0
         88        SEND_VAL                                                 10
         89        SEND_VAL                                                 31
         90        SEND_VAL                                                 2018
         91        DO_ICALL                                         $20     
         92        ADD_ARRAY_ELEMENT                                ~17     $20, 'park_period_end'
   24    93        ADD_ARRAY_ELEMENT                                ~17     2, 'check_num'
         94        ADD_ARRAY_ELEMENT                                ~15     ~17
   27    95        INIT_FCALL                                               'mktime'
         96        SEND_VAL                                                 0
         97        SEND_VAL                                                 0
         98        SEND_VAL                                                 0
         99        SEND_VAL                                                 10
        100        SEND_VAL                                                 12
        101        SEND_VAL                                                 2018
        102        DO_ICALL                                         $21     
        103        INIT_ARRAY                                       ~22     $21, 'file_submit_date'
   28   104        INIT_FCALL                                               'mktime'
        105        SEND_VAL                                                 0
        106        SEND_VAL                                                 0
        107        SEND_VAL                                                 0
        108        SEND_VAL                                                 10
        109        SEND_VAL                                                 17
        110        SEND_VAL                                                 2018
        111        DO_ICALL                                         $23     
        112        ADD_ARRAY_ELEMENT                                ~22     $23, 'pay_check_date'
   29   113        INIT_FCALL                                               'mktime'
        114        SEND_VAL                                                 0
        115        SEND_VAL                                                 0
        116        SEND_VAL                                                 0
        117        SEND_VAL                                                 11
        118        SEND_VAL                                                 1
        119        SEND_VAL                                                 2018
        120        DO_ICALL                                         $24     
        121        ADD_ARRAY_ELEMENT                                ~22     $24, 'park_period_start'
   30   122        INIT_FCALL                                               'mktime'
        123        SEND_VAL                                                 0
        124        SEND_VAL                                                 0
        125        SEND_VAL                                                 0
        126        SEND_VAL                                                 11
        127        SEND_VAL                                                 15
        128        SEND_VAL                                                 2018
        129        DO_ICALL                                         $25     
        130        ADD_ARRAY_ELEMENT                                ~22     $25, 'park_period_end'
   31   131        ADD_ARRAY_ELEMENT                                ~22     3, 'check_num'
        132        ADD_ARRAY_ELEMENT                                ~15     ~22
   34   133        INIT_FCALL                                               'mktime'
        134        SEND_VAL                                                 0
        135        SEND_VAL                                                 0
        136        SEND_VAL                                                 0
        137        SEND_VAL                                                 11
        138        SEND_VAL                                                 8
        139        SEND_VAL                                                 2018
        140        DO_ICALL                                         $26     
        141        INIT_ARRAY                                       ~27     $26, 'file_submit_date'
   35   142        INIT_FCALL                                               'mktime'
        143        SEND_VAL                                                 0
        144        SEND_VAL                                                 0
        145        SEND_VAL                                                 0
        146        SEND_VAL                                                 11
        147        SEND_VAL                                                 14
        148        SEND_VAL                                                 2018
        149        DO_ICALL                                         $28     
        150        ADD_ARRAY_ELEMENT                                ~27     $28, 'pay_check_date'
   36   151        INIT_FCALL                                               'mktime'
        152        SEND_VAL                                                 0
        153        SEND_VAL                                                 0
        154        SEND_VAL                                                 0
        155        SEND_VAL                                                 11
        156        SEND_VAL                                                 16
        157        SEND_VAL                                                 2018
        158        DO_ICALL                                         $29     
        159        ADD_ARRAY_ELEMENT                                ~27     $29, 'park_period_start'
   37   160        INIT_FCALL                                               'mktime'
        161        SEND_VAL                                                 0
        162        SEND_VAL                                                 0
        163        SEND_VAL                                                 0
        164        SEND_VAL                                                 11
        165        SEND_VAL                                                 30
        166        SEND_VAL                                                 2018
        167        DO_ICALL                                         $30     
        168        ADD_ARRAY_ELEMENT                                ~27     $30, 'park_period_end'
   38   169        ADD_ARRAY_ELEMENT                                ~27     4, 'check_num'
        170        ADD_ARRAY_ELEMENT                                ~15     ~27
   41   171        INIT_FCALL                                               'mktime'
        172        SEND_VAL                                                 0
        173        SEND_VAL                                                 0
        174        SEND_VAL                                                 0
        175        SEND_VAL                                                 11
        176        SEND_VAL                                                 21
        177        SEND_VAL                                                 2018
        178        DO_ICALL                                         $31     
        179        INIT_ARRAY                                       ~32     $31, 'file_submit_date'
   42   180        INIT_FCALL                                               'mktime'
        181        SEND_VAL                                                 0
        182        SEND_VAL                                                 0
        183        SEND_VAL                                                 0
        184        SEND_VAL                                                 11
        185        SEND_VAL                                                 28
        186        SEND_VAL                                                 2018
        187        DO_ICALL                                         $33     
        188        ADD_ARRAY_ELEMENT                                ~32     $33, 'pay_check_date'
   43   189        INIT_FCALL                                               'mktime'
        190        SEND_VAL                                                 0
        191        SEND_VAL                                                 0
        192        SEND_VAL                                                 0
        193        SEND_VAL                                                 12
        194        SEND_VAL                                                 1
        195        SEND_VAL                                                 2018
        196        DO_ICALL                                         $34     
        197        ADD_ARRAY_ELEMENT                                ~32     $34, 'park_period_start'
   44   198        INIT_FCALL                                               'mktime'
        199        SEND_VAL                                                 0
        200        SEND_VAL                                                 0
        201        SEND_VAL                                                 0
        202        SEND_VAL                                                 12
        203        SEND_VAL                                                 15
        204        SEND_VAL                                                 2018
        205        DO_ICALL                                         $35     
        206        ADD_ARRAY_ELEMENT                                ~32     $35, 'park_period_end'
   45   207        ADD_ARRAY_ELEMENT                                ~32     5, 'check_num'
        208        ADD_ARRAY_ELEMENT                                ~15     ~32
   48   209        INIT_FCALL                                               'mktime'
        210        SEND_VAL                                                 0
        211        SEND_VAL                                                 0
        212        SEND_VAL                                                 0
        213        SEND_VAL                                                 12
        214        SEND_VAL                                                 7
        215        SEND_VAL                                                 2018
        216        DO_ICALL                                         $36     
        217        INIT_ARRAY                                       ~37     $36, 'file_submit_date'
   49   218        INIT_FCALL                                               'mktime'
        219        SEND_VAL                                                 0
        220        SEND_VAL                                                 0
        221        SEND_VAL                                                 0
        222        SEND_VAL                                                 12
        223        SEND_VAL                                                 12
        224        SEND_VAL                                                 2018
        225        DO_ICALL                                         $38     
        226        ADD_ARRAY_ELEMENT                                ~37     $38, 'pay_check_date'
   50   227        INIT_FCALL                                               'mktime'
        228        SEND_VAL                                                 0
        229        SEND_VAL                                                 0
        230        SEND_VAL                                                 0
        231        SEND_VAL                                                 12
        232        SEND_VAL                                                 16
        233        SEND_VAL                                                 2018
        234        DO_ICALL                                         $39     
        235        ADD_ARRAY_ELEMENT                                ~37     $39, 'park_period_start'
   51   236        INIT_FCALL                                               'mktime'
        237        SEND_VAL                                                 0
        238        SEND_VAL                                                 0
        239        SEND_VAL                                                 0
        240        SEND_VAL                                                 12
        241        SEND_VAL                                                 31
        242        SEND_VAL                                                 2018
        243        DO_ICALL                                         $40     
        244        ADD_ARRAY_ELEMENT                                ~37     $40, 'park_period_end'
   52   245        ADD_ARRAY_ELEMENT                                ~37     6, 'check_num'
        246        ADD_ARRAY_ELEMENT                                ~15     ~37
        247        INIT_ARRAY                                       ~41     ~15, 'BW'
   10   248        ASSIGN                                                   !3, ~41
   61   249        INIT_FCALL_BY_NAME                                       'get_pay_cycle_for_active_date'
        250        SEND_VAR_EX                                              !0
        251        SEND_VAR_EX                                              !1
        252        CHECK_FUNC_ARG                                           
        253        FETCH_DIM_FUNC_ARG                               $43     !3, !2
        254        SEND_FUNC_ARG                                            $43
        255        DO_FCALL                                      0  $44     
        256        ASSIGN                                                   !4, $44
   62   257        ECHO                                                     !4
  142   258      > RETURN                                                   1

Function daysbetween:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aQYv7
function name:  daysBetween
number of ops:  17
compiled vars:  !0 = $dt1, !1 = $dt2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   71     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   72     2        INIT_FCALL                                               'date_diff'
   73     3        INIT_FCALL                                               'date_create'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $2      
          6        SEND_VAR                                                 $2
   74     7        INIT_FCALL                                               'date_create'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $3      
         10        SEND_VAR                                                 $3
         11        DO_ICALL                                         $4      
   75    12        INIT_METHOD_CALL                                         $4, 'format'
         13        SEND_VAL_EX                                              '%25a'
         14        DO_FCALL                                      0  $5      
         15      > RETURN                                                   $5
   76    16*     > 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/aQYv7
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
-------------------------------------------------------------------------------------
   78     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   82     3        ASSIGN                                                   !3, -1
   83     4        ASSIGN                                                   !4, -1
   91     5      > FE_RESET_R                                       $10     !2, ->31
          6    > > FE_FETCH_R                                       ~11     $10, !5, ->31
          7    >   ASSIGN                                                   !6, ~11
   94     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
   95    15    >   ASSIGN                                                   !3, !6
   99    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
  100    23    >   ASSIGN                                                   !4, !6
  104    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
   91    30      > JMP                                                      ->6
         31    >   FE_FREE                                                  $10
  107    32        CONCAT                                           ~26     'current_period_id+%3D+', !3
         33        CONCAT                                           ~27     ~26, '%0C%0D'
         34        ECHO                                                     ~27
  108    35        CONCAT                                           ~28     'active_period_id+%3D+', !4
         36        CONCAT                                           ~29     ~28, '%0C%0D'
         37        ECHO                                                     ~29
  109    38        CONCAT                                           ~30     'days_valid_in_active_period+%3D+', !7
         39        CONCAT                                           ~31     ~30, '%0C%0D'
         40        ECHO                                                     ~31
  110    41        CONCAT                                           ~32     'permit_active_date+%3D+', !1
         42        CONCAT                                           ~33     ~32, '%0C%0D'
         43        ECHO                                                     ~33
  111    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
  112    48      > RETURN                                                   ''
  120    49*     > RETURN                                                   null

End of function get_pay_cycle_for_active_date

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.92 ms | 1427 KiB | 20 Q