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 "\n our function: "; echo dateTimeDiff(date('Y-m-d'), '16-10-2013'); $datetime1 = date_create('now'); $datetime2 = date_create('16-10-2013'); $interval = date_diff($datetime1, $datetime2); echo "\n php function: "; echo $interval->format('%R%a dias');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DAGhR
function name:  (null)
number of ops:  28
compiled vars:  !0 = $datetime1, !1 = $datetime2, !2 = $interval
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ECHO                                                     '%0A+our+function%3A+'
   24     1        INIT_FCALL                                               'datetimediff'
          2        INIT_FCALL                                               'date'
          3        SEND_VAL                                                 'Y-m-d'
          4        DO_ICALL                                         $3      
          5        SEND_VAR                                                 $3
          6        SEND_VAL                                                 '16-10-2013'
          7        DO_FCALL                                      0  $4      
          8        ECHO                                                     $4
   26     9        INIT_FCALL                                               'date_create'
         10        SEND_VAL                                                 'now'
         11        DO_ICALL                                         $5      
         12        ASSIGN                                                   !0, $5
   27    13        INIT_FCALL                                               'date_create'
         14        SEND_VAL                                                 '16-10-2013'
         15        DO_ICALL                                         $7      
         16        ASSIGN                                                   !1, $7
   28    17        INIT_FCALL                                               'date_diff'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                         $9      
         21        ASSIGN                                                   !2, $9
   30    22        ECHO                                                     '%0A+php+function%3A+'
   31    23        INIT_METHOD_CALL                                         !2, 'format'
         24        SEND_VAL_EX                                              '%25R%25a+dias'
         25        DO_FCALL                                      0  $11     
         26        ECHO                                                     $11
         27      > 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/DAGhR
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
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      'Days'
    5     3        INIT_FCALL                                               'strtotime'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $7      
          6        ASSIGN                                                   !3, $7
    6     7        INIT_FCALL                                               'strtotime'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $9      
         10        ASSIGN                                                   !4, $9
    7    11        SUB                                              ~11     !4, !3
         12        ASSIGN                                                   !5, ~11
    9    13        ASSIGN                                                   !6, 86400
   10    14        IS_NOT_EQUAL                                             !2, 'Days'
         15      > JMPZ                                                     ~14, ->26
   11    16    >   DIV                                              ~15     !6, 24
         17        ASSIGN                                                   !6, ~15
   12    18        IS_NOT_EQUAL                                             !2, 'Hours'
         19      > JMPZ                                                     ~17, ->26
   13    20    >   DIV                                              ~18     !6, 60
         21        ASSIGN                                                   !6, ~18
   14    22        IS_NOT_EQUAL                                             !2, 'Minutes'
         23      > JMPZ                                                     ~20, ->26
   15    24    >   DIV                                              ~21     !6, 60
         25        ASSIGN                                                   !6, ~21
   20    26    >   INIT_FCALL                                               'round'
         27        DIV                                              ~23     !5, !6
         28        SEND_VAL                                                 ~23
         29        DO_ICALL                                         $24     
         30      > RETURN                                                   $24
   21    31*     > RETURN                                                   null

End of function datetimediff

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
357.41 ms | 1402 KiB | 25 Q