3v4l.org

run code in 300+ PHP versions simultaneously
<?php function dateTimeDiff($start, $end, $units = 'Days') { $start_ts = strtotime($start); $end_ts = strtotime($end); $diff = $end_ts - $start_ts; $divider = 86400; if ($units != 'Days') { $divider = $divider / 24; if ($units != 'Hours') { $divider = $divider / 60; if ($units != 'Minutes') { $divider = $divider / 60; } } } return round($diff / $divider); } echo dateTimeDiff(date('Y-m-d'), '13-11-2013'); $datetime1 = date_create('now'); $datetime2 = date_create('13-11-2013'); $interval = date_diff($datetime1, $datetime2); echo "\n"; echo $interval->format('%R%a dias');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/clXh4
function name:  (null)
number of ops:  27
compiled vars:  !0 = $datetime1, !1 = $datetime2, !2 = $interval
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   INIT_FCALL                                               'datetimediff'
          1        INIT_FCALL                                               'date'
          2        SEND_VAL                                                 'Y-m-d'
          3        DO_ICALL                                         $3      
          4        SEND_VAR                                                 $3
          5        SEND_VAL                                                 '13-11-2013'
          6        DO_FCALL                                      0  $4      
          7        ECHO                                                     $4
   24     8        INIT_FCALL                                               'date_create'
          9        SEND_VAL                                                 'now'
         10        DO_ICALL                                         $5      
         11        ASSIGN                                                   !0, $5
   25    12        INIT_FCALL                                               'date_create'
         13        SEND_VAL                                                 '13-11-2013'
         14        DO_ICALL                                         $7      
         15        ASSIGN                                                   !1, $7
   26    16        INIT_FCALL                                               'date_diff'
         17        SEND_VAR                                                 !0
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                         $9      
         20        ASSIGN                                                   !2, $9
   28    21        ECHO                                                     '%0A'
   29    22        INIT_METHOD_CALL                                         !2, 'format'
         23        SEND_VAL_EX                                              '%25R%25a+dias'
         24        DO_FCALL                                      0  $11     
         25        ECHO                                                     $11
         26      > RETURN                                                   1

Function datetimediff:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 26
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 26
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 26
Branch analysis from position: 26
filename:       /in/clXh4
function name:  dateTimeDiff
number of ops:  32
compiled vars:  !0 = $start, !1 = $end, !2 = $units, !3 = $start_ts, !4 = $end_ts, !5 = $diff, !6 = $divider
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      'Days'
    4     3        INIT_FCALL                                               'strtotime'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $7      
          6        ASSIGN                                                   !3, $7
    5     7        INIT_FCALL                                               'strtotime'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $9      
         10        ASSIGN                                                   !4, $9
    6    11        SUB                                              ~11     !4, !3
         12        ASSIGN                                                   !5, ~11
    8    13        ASSIGN                                                   !6, 86400
    9    14        IS_NOT_EQUAL                                             !2, 'Days'
         15      > JMPZ                                                     ~14, ->26
   10    16    >   DIV                                              ~15     !6, 24
         17        ASSIGN                                                   !6, ~15
   11    18        IS_NOT_EQUAL                                             !2, 'Hours'
         19      > JMPZ                                                     ~17, ->26
   12    20    >   DIV                                              ~18     !6, 60
         21        ASSIGN                                                   !6, ~18
   13    22        IS_NOT_EQUAL                                             !2, 'Minutes'
         23      > JMPZ                                                     ~20, ->26
   14    24    >   DIV                                              ~21     !6, 60
         25        ASSIGN                                                   !6, ~21
   19    26    >   INIT_FCALL                                               'round'
         27        DIV                                              ~23     !5, !6
         28        SEND_VAL                                                 ~23
         29        DO_ICALL                                         $24     
         30      > RETURN                                                   $24
   20    31*     > RETURN                                                   null

End of function datetimediff

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.51 ms | 1403 KiB | 24 Q