3v4l.org

run code in 300+ PHP versions simultaneously
<?php function strToDuration($str) { sscanf($str, '%d:%d:%d', $hours, $minutes, $seconds); return $seconds + ($minutes * 60) + ($hours * 60 * 60); } function durationToStr($duration) { $hours = floor($duration / (60 * 60)); $seconds = $duration % (60 * 60); $minutes = floor($seconds / 60); $seconds %= 60; return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds); } $morning = '01:05:12'; $evening = '14:05:29'; echo durationToStr(strToDuration($morning) + strToDuration($evening));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sgXLD
function name:  (null)
number of ops:  14
compiled vars:  !0 = $morning, !1 = $evening
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                   !0, '01%3A05%3A12'
   17     1        ASSIGN                                                   !1, '14%3A05%3A29'
   19     2        INIT_FCALL                                               'durationtostr'
          3        INIT_FCALL                                               'strtoduration'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $4      
          6        INIT_FCALL                                               'strtoduration'
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0  $5      
          9        ADD                                              ~6      $4, $5
         10        SEND_VAL                                                 ~6
         11        DO_FCALL                                      0  $7      
         12        ECHO                                                     $7
         13      > RETURN                                                   1

Function strtoduration:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sgXLD
function name:  strToDuration
number of ops:  15
compiled vars:  !0 = $str, !1 = $hours, !2 = $minutes, !3 = $seconds
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'sscanf'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '%25d%3A%25d%3A%25d'
          4        SEND_REF                                                 !1
          5        SEND_REF                                                 !2
          6        SEND_REF                                                 !3
          7        DO_ICALL                                                 
    5     8        MUL                                              ~5      !2, 60
          9        ADD                                              ~6      !3, ~5
         10        MUL                                              ~7      !1, 60
         11        MUL                                              ~8      ~7, 60
         12        ADD                                              ~9      ~6, ~8
         13      > RETURN                                                   ~9
    6    14*     > RETURN                                                   null

End of function strtoduration

Function durationtostr:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sgXLD
function name:  durationToStr
number of ops:  22
compiled vars:  !0 = $duration, !1 = $hours, !2 = $seconds, !3 = $minutes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
    9     1        INIT_FCALL                                               'floor'
          2        DIV                                              ~4      !0, 3600
          3        SEND_VAL                                                 ~4
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !1, $5
   10     6        MOD                                              ~7      !0, 3600
          7        ASSIGN                                                   !2, ~7
   11     8        INIT_FCALL                                               'floor'
          9        DIV                                              ~9      !2, 60
         10        SEND_VAL                                                 ~9
         11        DO_ICALL                                         $10     
         12        ASSIGN                                                   !3, $10
   12    13        ASSIGN_OP                                     5          !2, 60
   13    14        INIT_FCALL                                               'sprintf'
         15        SEND_VAL                                                 '%2502d%3A%2502d%3A%2502d'
         16        SEND_VAR                                                 !1
         17        SEND_VAR                                                 !3
         18        SEND_VAR                                                 !2
         19        DO_ICALL                                         $13     
         20      > RETURN                                                   $13
   14    21*     > RETURN                                                   null

End of function durationtostr

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.77 ms | 1403 KiB | 22 Q