3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class ArrayUtils { private static $visited = []; private static $sum = 0; public static function containsSum(array $data, int $sum): bool { self::$visited = []; self::$sum = $sum; return array_reduce($data, 'ArrayUtils::reduce', false); } private static function reduce(bool $carry, int $item): bool { $carry |= isset(self::$visited[self::$sum - $item]); self::$visited[$item] = true; return (bool) $carry; } } $data = range(0, 49999); shuffle($data); var_dump(ArrayUtils::containsSum($data, 1220)); var_dump(ArrayUtils::containsSum($data, -7));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ye139
function name:  (null)
number of ops:  23
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   INIT_FCALL                                               'range'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 49999
          3        DO_ICALL                                         $1      
          4        ASSIGN                                                   !0, $1
   28     5        INIT_FCALL                                               'shuffle'
          6        SEND_REF                                                 !0
          7        DO_ICALL                                                 
   29     8        INIT_FCALL                                               'var_dump'
          9        INIT_STATIC_METHOD_CALL                                  'ArrayUtils', 'containsSum'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 1220
         12        DO_FCALL                                      0  $4      
         13        SEND_VAR                                                 $4
         14        DO_ICALL                                                 
   30    15        INIT_FCALL                                               'var_dump'
         16        INIT_STATIC_METHOD_CALL                                  'ArrayUtils', 'containsSum'
         17        SEND_VAR                                                 !0
         18        SEND_VAL                                                 -7
         19        DO_FCALL                                      0  $6      
         20        SEND_VAR                                                 $6
         21        DO_ICALL                                                 
         22      > RETURN                                                   1

Class ArrayUtils:
Function containssum:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ye139
function name:  containsSum
number of ops:  15
compiled vars:  !0 = $data, !1 = $sum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   11     2        ASSIGN_STATIC_PROP                                       'visited'
          3        OP_DATA                                                  <array>
   12     4        ASSIGN_STATIC_PROP                                       'sum'
          5        OP_DATA                                                  !1
   14     6        INIT_FCALL                                               'array_reduce'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 'ArrayUtils%3A%3Areduce'
          9        SEND_VAL                                                 <false>
         10        DO_ICALL                                         $4      
         11        VERIFY_RETURN_TYPE                                       $4
         12      > RETURN                                                   $4
   15    13*       VERIFY_RETURN_TYPE                                       
         14*     > RETURN                                                   null

End of function containssum

Function reduce:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ye139
function name:  reduce
number of ops:  15
compiled vars:  !0 = $carry, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   19     2        FETCH_STATIC_PROP_R          unknown             ~3      'sum'
          3        SUB                                              ~4      ~3, !1
          4        FETCH_STATIC_PROP_IS                             ~2      'visited'
          5        ISSET_ISEMPTY_DIM_OBJ                         0  ~5      ~2, ~4
          6        ASSIGN_OP                                     9          !0, ~5
   21     7        FETCH_STATIC_PROP_W          unknown             $7      'visited'
          8        ASSIGN_DIM                                               $7, !1
          9        OP_DATA                                                  <true>
   23    10        BOOL                                             ~9      !0
         11        VERIFY_RETURN_TYPE                                       ~9
         12      > RETURN                                                   ~9
   24    13*       VERIFY_RETURN_TYPE                                       
         14*     > RETURN                                                   null

End of function reduce

End of class ArrayUtils.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.44 ms | 1400 KiB | 21 Q