3v4l.org

run code in 300+ PHP versions simultaneously
<?php function calcDays($startdate, $enddate) { $first = $startdate < $enddate ? $startdate : $enddate; $second = $startdate < $enddate ? $enddate : $startdate; $inbetween = $second - $first; $i[0] = 60; $i[1] = 24; $i[2] = 7; $i[3] = date('t', strtotime('-1 month', $second)); $i[4] = date('L', strtotime('-1 year', $second)) ? 366 : 365; $i[5] = array(31, (date('L', strtotime('-1 year', $second)) ? 28 : 29), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $months = 0; $days = 0; $temp = floor($inbetween / $i[0] / $i[0] / $i[1]); $tempMonth = date('n', strtotime('-1 year', $second)) - 1; while(TRUE) { var_dump($temp); if($temp >= $i[5][$tempMonth]) { $months += 1; $temp -= $i[5][$tempMonth]; } else { $days = $temp; break; } $tempMonth = $tempMonth < 10 ? $tempMonth + 1 : 0; } $years = date('Y', $second) - date('Y', $first) + $months / 12; $months = $months % 12; $hours = floor($inbetween / $i[0] / $i[0] % $i[1]); $minutes = floor($inbetween / $i[0] % $i[0]); $seconds = $inbetween % $i[0]; return $years . " years " . $months . " months " . $days . " days " . $hours . " hours " . $minutes . " minutes " . $seconds . " seconds"; } echo calcDays(1388389157, 1704094758);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/r6NPK
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   INIT_FCALL                                               'calcdays'
          1        SEND_VAL                                                 1388389157
          2        SEND_VAL                                                 1704094758
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
          5      > RETURN                                                   1

Function calcdays:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 58
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 116
Branch analysis from position: 116
2 jumps found. (Code = 44) Position 1 = 117, Position 2 = 95
Branch analysis from position: 117
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 95
2 jumps found. (Code = 43) Position 1 = 102, Position 2 = 107
Branch analysis from position: 102
1 jumps found. (Code = 42) Position 1 = 109
Branch analysis from position: 109
2 jumps found. (Code = 43) Position 1 = 111, Position 2 = 114
Branch analysis from position: 111
1 jumps found. (Code = 42) Position 1 = 115
Branch analysis from position: 115
2 jumps found. (Code = 44) Position 1 = 117, Position 2 = 95
Branch analysis from position: 117
Branch analysis from position: 95
Branch analysis from position: 114
2 jumps found. (Code = 44) Position 1 = 117, Position 2 = 95
Branch analysis from position: 117
Branch analysis from position: 95
Branch analysis from position: 107
1 jumps found. (Code = 42) Position 1 = 117
Branch analysis from position: 117
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 116
Branch analysis from position: 116
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 58
Branch analysis from position: 56
Branch analysis from position: 58
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
Branch analysis from position: 43
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
Branch analysis from position: 12
filename:       /in/r6NPK
function name:  calcDays
number of ops:  165
compiled vars:  !0 = $startdate, !1 = $enddate, !2 = $first, !3 = $second, !4 = $inbetween, !5 = $i, !6 = $months, !7 = $days, !8 = $temp, !9 = $tempMonth, !10 = $years, !11 = $hours, !12 = $minutes, !13 = $seconds
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        IS_SMALLER                                               !0, !1
          3      > JMPZ                                                     ~14, ->6
          4    >   QM_ASSIGN                                        ~15     !0
          5      > JMP                                                      ->7
          6    >   QM_ASSIGN                                        ~15     !1
          7    >   ASSIGN                                                   !2, ~15
    5     8        IS_SMALLER                                               !0, !1
          9      > JMPZ                                                     ~17, ->12
         10    >   QM_ASSIGN                                        ~18     !1
         11      > JMP                                                      ->13
         12    >   QM_ASSIGN                                        ~18     !0
         13    >   ASSIGN                                                   !3, ~18
    6    14        SUB                                              ~20     !3, !2
         15        ASSIGN                                                   !4, ~20
    8    16        ASSIGN_DIM                                               !5, 0
         17        OP_DATA                                                  60
    9    18        ASSIGN_DIM                                               !5, 1
         19        OP_DATA                                                  24
   10    20        ASSIGN_DIM                                               !5, 2
         21        OP_DATA                                                  7
   11    22        INIT_FCALL                                               'date'
         23        SEND_VAL                                                 't'
         24        INIT_FCALL                                               'strtotime'
         25        SEND_VAL                                                 '-1+month'
         26        SEND_VAR                                                 !3
         27        DO_ICALL                                         $26     
         28        SEND_VAR                                                 $26
         29        DO_ICALL                                         $27     
         30        ASSIGN_DIM                                               !5, 3
         31        OP_DATA                                                  $27
   12    32        INIT_FCALL                                               'date'
         33        SEND_VAL                                                 'L'
         34        INIT_FCALL                                               'strtotime'
         35        SEND_VAL                                                 '-1+year'
         36        SEND_VAR                                                 !3
         37        DO_ICALL                                         $29     
         38        SEND_VAR                                                 $29
         39        DO_ICALL                                         $30     
         40      > JMPZ                                                     $30, ->43
         41    >   QM_ASSIGN                                        ~31     366
         42      > JMP                                                      ->44
         43    >   QM_ASSIGN                                        ~31     365
         44    >   ASSIGN_DIM                                               !5, 4
         45        OP_DATA                                                  ~31
   13    46        INIT_ARRAY                                       ~33     31
         47        INIT_FCALL                                               'date'
         48        SEND_VAL                                                 'L'
         49        INIT_FCALL                                               'strtotime'
         50        SEND_VAL                                                 '-1+year'
         51        SEND_VAR                                                 !3
         52        DO_ICALL                                         $34     
         53        SEND_VAR                                                 $34
         54        DO_ICALL                                         $35     
         55      > JMPZ                                                     $35, ->58
         56    >   QM_ASSIGN                                        ~36     28
         57      > JMP                                                      ->59
         58    >   QM_ASSIGN                                        ~36     29
         59    >   ADD_ARRAY_ELEMENT                                ~33     ~36
         60        ADD_ARRAY_ELEMENT                                ~33     31
         61        ADD_ARRAY_ELEMENT                                ~33     30
         62        ADD_ARRAY_ELEMENT                                ~33     31
         63        ADD_ARRAY_ELEMENT                                ~33     30
         64        ADD_ARRAY_ELEMENT                                ~33     31
         65        ADD_ARRAY_ELEMENT                                ~33     31
         66        ADD_ARRAY_ELEMENT                                ~33     30
         67        ADD_ARRAY_ELEMENT                                ~33     31
         68        ADD_ARRAY_ELEMENT                                ~33     30
         69        ADD_ARRAY_ELEMENT                                ~33     31
         70        ASSIGN_DIM                                               !5, 5
         71        OP_DATA                                                  ~33
   15    72        ASSIGN                                                   !6, 0
   16    73        ASSIGN                                                   !7, 0
   18    74        INIT_FCALL                                               'floor'
         75        FETCH_DIM_R                                      ~39     !5, 0
         76        DIV                                              ~40     !4, ~39
         77        FETCH_DIM_R                                      ~41     !5, 0
         78        DIV                                              ~42     ~40, ~41
         79        FETCH_DIM_R                                      ~43     !5, 1
         80        DIV                                              ~44     ~42, ~43
         81        SEND_VAL                                                 ~44
         82        DO_ICALL                                         $45     
         83        ASSIGN                                                   !8, $45
   19    84        INIT_FCALL                                               'date'
         85        SEND_VAL                                                 'n'
         86        INIT_FCALL                                               'strtotime'
         87        SEND_VAL                                                 '-1+year'
         88        SEND_VAR                                                 !3
         89        DO_ICALL                                         $47     
         90        SEND_VAR                                                 $47
         91        DO_ICALL                                         $48     
         92        SUB                                              ~49     $48, 1
         93        ASSIGN                                                   !9, ~49
   21    94      > JMP                                                      ->116
   22    95    >   INIT_FCALL                                               'var_dump'
         96        SEND_VAR                                                 !8
         97        DO_ICALL                                                 
   23    98        FETCH_DIM_R                                      ~52     !5, 5
         99        FETCH_DIM_R                                      ~53     ~52, !9
        100        IS_SMALLER_OR_EQUAL                                      ~53, !8
        101      > JMPZ                                                     ~54, ->107
   24   102    >   ASSIGN_OP                                     1          !6, 1
   25   103        FETCH_DIM_R                                      ~56     !5, 5
        104        FETCH_DIM_R                                      ~57     ~56, !9
        105        ASSIGN_OP                                     2          !8, ~57
        106      > JMP                                                      ->109
   27   107    >   ASSIGN                                                   !7, !8
   28   108      > JMP                                                      ->117
   31   109    >   IS_SMALLER                                               !9, 10
        110      > JMPZ                                                     ~60, ->114
        111    >   ADD                                              ~61     !9, 1
        112        QM_ASSIGN                                        ~62     ~61
        113      > JMP                                                      ->115
        114    >   QM_ASSIGN                                        ~62     0
        115    >   ASSIGN                                                   !9, ~62
   21   116    > > JMPNZ                                                    <true>, ->95
   35   117    >   INIT_FCALL                                               'date'
        118        SEND_VAL                                                 'Y'
        119        SEND_VAR                                                 !3
        120        DO_ICALL                                         $64     
        121        INIT_FCALL                                               'date'
        122        SEND_VAL                                                 'Y'
        123        SEND_VAR                                                 !2
        124        DO_ICALL                                         $65     
        125        SUB                                              ~66     $64, $65
        126        DIV                                              ~67     !6, 12
        127        ADD                                              ~68     ~66, ~67
        128        ASSIGN                                                   !10, ~68
   36   129        MOD                                              ~70     !6, 12
        130        ASSIGN                                                   !6, ~70
   38   131        INIT_FCALL                                               'floor'
        132        FETCH_DIM_R                                      ~72     !5, 0
        133        DIV                                              ~73     !4, ~72
        134        FETCH_DIM_R                                      ~74     !5, 0
        135        DIV                                              ~75     ~73, ~74
        136        FETCH_DIM_R                                      ~76     !5, 1
        137        MOD                                              ~77     ~75, ~76
        138        SEND_VAL                                                 ~77
        139        DO_ICALL                                         $78     
        140        ASSIGN                                                   !11, $78
   39   141        INIT_FCALL                                               'floor'
        142        FETCH_DIM_R                                      ~80     !5, 0
        143        DIV                                              ~81     !4, ~80
        144        FETCH_DIM_R                                      ~82     !5, 0
        145        MOD                                              ~83     ~81, ~82
        146        SEND_VAL                                                 ~83
        147        DO_ICALL                                         $84     
        148        ASSIGN                                                   !12, $84
   40   149        FETCH_DIM_R                                      ~86     !5, 0
        150        MOD                                              ~87     !4, ~86
        151        ASSIGN                                                   !13, ~87
   42   152        CONCAT                                           ~89     !10, '+years+'
        153        CONCAT                                           ~90     ~89, !6
        154        CONCAT                                           ~91     ~90, '+months+'
        155        CONCAT                                           ~92     ~91, !7
        156        CONCAT                                           ~93     ~92, '+days+'
        157        CONCAT                                           ~94     ~93, !11
        158        CONCAT                                           ~95     ~94, '+hours+'
        159        CONCAT                                           ~96     ~95, !12
        160        CONCAT                                           ~97     ~96, '+minutes+'
        161        CONCAT                                           ~98     ~97, !13
        162        CONCAT                                           ~99     ~98, '+seconds'
        163      > RETURN                                                   ~99
   43   164*     > RETURN                                                   null

End of function calcdays

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.32 ms | 1415 KiB | 22 Q