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

End of function calcdays

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.12 ms | 1406 KiB | 22 Q