3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $diff = strtotime('2015-04-14T10:55:28+01:00') - strtotime('2015-04-10T13:19:03+01:00'); function secs_to_h($secs) { $units = array( "week" => 7*24*3600, "day" => 24*3600, "hour" => 3600, "minute" => 60, "second" => 1, ); // specifically handle zero if ( $secs == 0 ) return "0 seconds"; $s = ""; foreach ( $units as $name => $divisor ) { if ( $quot = intval($secs / $divisor) ) { $s .= "$quot $name"; $s .= (abs($quot) > 1 ? "s" : "") . ", "; $secs -= $quot * $divisor; } } return substr($s, 0, -2); } var_dump($diff, gmdate("H",$diff), secs_to_h(6811.5));
based on 3dk9P
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/PvvKY
function name:  (null)
number of ops:  22
compiled vars:  !0 = $diff
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   INIT_FCALL                                               'strtotime'
         1        SEND_VAL                                                 '2015-04-14T10%3A55%3A28%2B01%3A00'
         2        DO_ICALL                                         $1      
         3        INIT_FCALL                                               'strtotime'
         4        SEND_VAL                                                 '2015-04-10T13%3A19%3A03%2B01%3A00'
         5        DO_ICALL                                         $2      
         6        SUB                                              ~3      $1, $2
         7        ASSIGN                                                   !0, ~3
   4     8        NOP                                                      
  30     9        INIT_FCALL                                               'var_dump'
        10        SEND_VAR                                                 !0
        11        INIT_FCALL                                               'gmdate'
        12        SEND_VAL                                                 'H'
        13        SEND_VAR                                                 !0
        14        DO_ICALL                                         $5      
        15        SEND_VAR                                                 $5
        16        INIT_FCALL                                               'secs_to_h'
        17        SEND_VAL                                                 6811.5
        18        DO_FCALL                                      0  $6      
        19        SEND_VAR                                                 $6
        20        DO_ICALL                                                 
        21      > RETURN                                                   1

Function secs_to_h:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
Jump found. Position 1 = -2
Branch analysis from position: 5
Jump found. Position 1 = 7, Position 2 = 32
Branch analysis from position: 7
Jump found. Position 1 = 8, Position 2 = 32
Branch analysis from position: 8
Jump found. Position 1 = 15, Position 2 = 31
Branch analysis from position: 15
Jump found. Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
Jump found. Position 1 = 27
Branch analysis from position: 27
Jump found. Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 26
Jump found. Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 31
Branch analysis from position: 32
Jump found. Position 1 = -2
Branch analysis from position: 32
filename:       /in/PvvKY
function name:  secs_to_h
number of ops:  40
compiled vars:  !0 = $secs, !1 = $units, !2 = $s, !3 = $divisor, !4 = $name, !5 = $quot
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   4     0  E >   RECV                                             !0      
   7     1        ASSIGN                                                   !1, <array>
  15     2        IS_EQUAL                                         ~7      !0, 0
         3      > JMPZ                                                     ~7, ->5
         4    > > RETURN                                                   '0+seconds'
  17     5    >   ASSIGN                                                   !2, ''
  19     6      > FE_RESET_R                                       $9      !1, ->32
         7    > > FE_FETCH_R                                               $9, !3, ->32
         8    >   ASSIGN                                                   !4, ~10
  20     9        INIT_FCALL                                               'intval'
        10        DIV                                              ~12     !0, !3
        11        SEND_VAL                                                 ~12
        12        DO_ICALL                                         $13     
        13        ASSIGN                                           $14     !5, $13
        14      > JMPZ                                                     $14, ->31
  21    15    >   ROPE_INIT                                     3  ~16     !5
        16        ROPE_ADD                                      1  ~16     ~16, '+'
        17        ROPE_END                                      2  ~15     ~16, !4
        18        ASSIGN_CONCAT                                 0          !2, ~15
  22    19        INIT_FCALL                                               'abs'
        20        SEND_VAR                                                 !5
        21        DO_ICALL                                         $19     
        22        IS_SMALLER                                       ~20     1, $19
        23      > JMPZ                                                     ~20, ->26
        24    >   QM_ASSIGN                                        ~21     's'
        25      > JMP                                                      ->27
        26    >   QM_ASSIGN                                        ~21     ''
        27    >   CONCAT                                           ~22     ~21, '%2C+'
        28        ASSIGN_CONCAT                                 0          !2, ~22
  23    29        MUL                                              ~24     !5, !3
        30        ASSIGN_SUB                                    0          !0, ~24
        31    > > JMP                                                      ->7
        32    >   FE_FREE                                                  $9
  27    33        INIT_FCALL                                               'substr'
        34        SEND_VAR                                                 !2
        35        SEND_VAL                                                 0
        36        SEND_VAL                                                 -2
        37        DO_ICALL                                         $26     
        38      > RETURN                                                   $26
  28    39*     > RETURN                                                   null

End of function secs_to_h

Generated using Vulcan Logic Dumper, using php 7.3.0