3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Set timezone date_default_timezone_set("UTC"); // Time format is UNIX timestamp or // PHP strtotime compatible strings function dateDiff($time1, $time2, $precision = 6) { // If not numeric then convert texts to unix timestamps if (!is_int($time1)) { $time1 = strtotime($time1); } if (!is_int($time2)) { $time2 = strtotime($time2); } // If time1 is bigger than time2 // Then swap time1 and time2 if ($time1 > $time2) { $ttime = $time1; $time1 = $time2; $time2 = $ttime; } // Set up intervals and diffs arrays $intervals = array('year','month','day','hour','minute','second'); $diffs = array(); // Loop thru all intervals foreach ($intervals as $interval) { // Create temp time from time1 and interval $ttime = strtotime('+1 ' . $interval, $time1); // Set initial values $add = 1; $looped = 0; // Loop until temp time is smaller than time2 while ($time2 >= $ttime) { // Create new temp time from time1 and interval $add++; $ttime = strtotime("+" . $add . " " . $interval, $time1); $looped++; } $time1 = strtotime("+" . $looped . " " . $interval, $time1); $diffs[$interval] = $looped; } $count = 0; $times = array(); // Loop thru all diffs foreach ($diffs as $interval => $value) { // Break if we have needed precission if ($count >= $precision) { break; } // Add value and interval // if value is bigger than 0 if ($value > 0) { // Add s if value is not 1 if ($value != 1) { $interval .= "s"; } // Add value and interval to times array $times[] = $value . " " . $interval; $count++; } } // Return string with times return implode(", ", $times); } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9b3b9
function name:  (null)
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL                                               'date_default_timezone_set'
          1        SEND_VAL                                                 'UTC'
          2        DO_ICALL                                                 
   73     3      > RETURN                                                   1

Function datediff:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 58
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 58
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 35
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 35
Branch analysis from position: 47
Branch analysis from position: 35
Branch analysis from position: 58
2 jumps found. (Code = 77) Position 1 = 62, Position 2 = 78
Branch analysis from position: 62
2 jumps found. (Code = 78) Position 1 = 63, Position 2 = 78
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 67
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 67
2 jumps found. (Code = 43) Position 1 = 69, Position 2 = 77
Branch analysis from position: 69
2 jumps found. (Code = 43) Position 1 = 71, Position 2 = 72
Branch analysis from position: 71
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
Branch analysis from position: 72
Branch analysis from position: 77
Branch analysis from position: 78
Branch analysis from position: 78
Branch analysis from position: 58
Branch analysis from position: 22
Branch analysis from position: 17
Branch analysis from position: 10
filename:       /in/9b3b9
function name:  dateDiff
number of ops:  85
compiled vars:  !0 = $time1, !1 = $time2, !2 = $precision, !3 = $ttime, !4 = $intervals, !5 = $diffs, !6 = $interval, !7 = $add, !8 = $looped, !9 = $count, !10 = $times, !11 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      6
   10     3        TYPE_CHECK                                   16  ~12     !0
          4        BOOL_NOT                                         ~13     ~12
          5      > JMPZ                                                     ~13, ->10
   11     6    >   INIT_FCALL                                               'strtotime'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $14     
          9        ASSIGN                                                   !0, $14
   13    10    >   TYPE_CHECK                                   16  ~16     !1
         11        BOOL_NOT                                         ~17     ~16
         12      > JMPZ                                                     ~17, ->17
   14    13    >   INIT_FCALL                                               'strtotime'
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $18     
         16        ASSIGN                                                   !1, $18
   19    17    >   IS_SMALLER                                               !1, !0
         18      > JMPZ                                                     ~20, ->22
   20    19    >   ASSIGN                                                   !3, !0
   21    20        ASSIGN                                                   !0, !1
   22    21        ASSIGN                                                   !1, !3
   26    22    >   ASSIGN                                                   !4, <array>
   27    23        ASSIGN                                                   !5, <array>
   30    24      > FE_RESET_R                                       $26     !4, ->58
         25    > > FE_FETCH_R                                               $26, !6, ->58
   32    26    >   INIT_FCALL                                               'strtotime'
         27        CONCAT                                           ~27     '%2B1+', !6
         28        SEND_VAL                                                 ~27
         29        SEND_VAR                                                 !0
         30        DO_ICALL                                         $28     
         31        ASSIGN                                                   !3, $28
   34    32        ASSIGN                                                   !7, 1
   35    33        ASSIGN                                                   !8, 0
   37    34      > JMP                                                      ->45
   39    35    >   PRE_INC                                                  !7
   40    36        INIT_FCALL                                               'strtotime'
         37        CONCAT                                           ~33     '%2B', !7
         38        CONCAT                                           ~34     ~33, '+'
         39        CONCAT                                           ~35     ~34, !6
         40        SEND_VAL                                                 ~35
         41        SEND_VAR                                                 !0
         42        DO_ICALL                                         $36     
         43        ASSIGN                                                   !3, $36
   41    44        PRE_INC                                                  !8
   37    45    >   IS_SMALLER_OR_EQUAL                                      !3, !1
         46      > JMPNZ                                                    ~39, ->35
   44    47    >   INIT_FCALL                                               'strtotime'
         48        CONCAT                                           ~40     '%2B', !8
         49        CONCAT                                           ~41     ~40, '+'
         50        CONCAT                                           ~42     ~41, !6
         51        SEND_VAL                                                 ~42
         52        SEND_VAR                                                 !0
         53        DO_ICALL                                         $43     
         54        ASSIGN                                                   !0, $43
   45    55        ASSIGN_DIM                                               !5, !6
         56        OP_DATA                                                  !8
   30    57      > JMP                                                      ->25
         58    >   FE_FREE                                                  $26
   48    59        ASSIGN                                                   !9, 0
   49    60        ASSIGN                                                   !10, <array>
   51    61      > FE_RESET_R                                       $48     !5, ->78
         62    > > FE_FETCH_R                                       ~49     $48, !11, ->78
         63    >   ASSIGN                                                   !6, ~49
   53    64        IS_SMALLER_OR_EQUAL                                      !2, !9
         65      > JMPZ                                                     ~51, ->67
   54    66    > > JMP                                                      ->78
   58    67    >   IS_SMALLER                                               0, !11
         68      > JMPZ                                                     ~52, ->77
   60    69    >   IS_NOT_EQUAL                                             !11, 1
         70      > JMPZ                                                     ~53, ->72
   61    71    >   ASSIGN_OP                                     8          !6, 's'
   64    72    >   CONCAT                                           ~56     !11, '+'
         73        CONCAT                                           ~57     ~56, !6
         74        ASSIGN_DIM                                               !10
         75        OP_DATA                                                  ~57
   65    76        PRE_INC                                                  !9
   51    77    > > JMP                                                      ->62
         78    >   FE_FREE                                                  $48
   70    79        INIT_FCALL                                               'implode'
         80        SEND_VAL                                                 '%2C+'
         81        SEND_VAR                                                 !10
         82        DO_ICALL                                         $59     
         83      > RETURN                                                   $59
   71    84*     > RETURN                                                   null

End of function datediff

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.53 ms | 1408 KiB | 19 Q