3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [3, 2, 1, 0, -1, -2, -3, -4, 10, -1, -2, -3]; var_dump(find_max_sum_interval($arr)); function find_max_sum_interval($arr) { $sum = $arr[0]; $max = $sum; for ($i = 1; $i < count($arr); $i++) { if ($sum > 0) { $sum += $arr[$i]; } else { $sum = $arr[$i]; } if ($max < $sum) { $max = $sum; } } return $max; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/X0gk7
function name:  (null)
number of ops:  8
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    3     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL_BY_NAME                                       'find_max_sum_interval'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
   21     7      > RETURN                                                   1

Function find_max_sum_interval:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 6
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 6
Branch analysis from position: 20
Branch analysis from position: 6
Branch analysis from position: 16
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
Branch analysis from position: 16
filename:       /in/X0gk7
function name:  find_max_sum_interval
number of ops:  22
compiled vars:  !0 = $arr, !1 = $sum, !2 = $max, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        FETCH_DIM_R                                      ~4      !0, 0
          2        ASSIGN                                                   !1, ~4
    7     3        ASSIGN                                                   !2, !1
    9     4        ASSIGN                                                   !3, 1
          5      > JMP                                                      ->17
   10     6    >   IS_SMALLER                                               0, !1
          7      > JMPZ                                                     ~8, ->11
   11     8    >   FETCH_DIM_R                                      ~9      !0, !3
          9        ASSIGN_OP                                     1          !1, ~9
         10      > JMP                                                      ->13
   13    11    >   FETCH_DIM_R                                      ~11     !0, !3
         12        ASSIGN                                                   !1, ~11
   15    13    >   IS_SMALLER                                               !2, !1
         14      > JMPZ                                                     ~13, ->16
   16    15    >   ASSIGN                                                   !2, !1
    9    16    >   PRE_INC                                                  !3
         17    >   COUNT                                            ~16     !0
         18        IS_SMALLER                                               !3, ~16
         19      > JMPNZ                                                    ~17, ->6
   20    20    > > RETURN                                                   !2
   21    21*     > RETURN                                                   null

End of function find_max_sum_interval

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.85 ms | 1400 KiB | 15 Q