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

End of function calcdays

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.38 ms | 1415 KiB | 22 Q