3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ 2 => 5, 4 => 1, 8 => 3, 0 => 17, 9 => 2, 11 => 67 ]; $ranges = ['1-5', '6-10', '1000-5000']; var_export( array_reduce( $ranges, fn($result, $range) => $result + [$range => array_sum(array_intersect_key($array, array_flip(range(...sscanf($range, '%d-%d')))))], [] ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3SiGo
function name:  (null)
number of ops:  13
compiled vars:  !0 = $array, !1 = $ranges
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   12     1        ASSIGN                                                       !1, <array>
   14     2        INIT_FCALL                                                   'var_export'
   15     3        INIT_FCALL                                                   'array_reduce'
   16     4        SEND_VAR                                                     !1
   17     5        DECLARE_LAMBDA_FUNCTION                              ~4      [0]
          6        BIND_LEXICAL                                                 ~4, !0
   18     7        SEND_VAL                                                     ~4
   19     8        SEND_VAL                                                     <array>
   15     9        DO_ICALL                                             $5      
   19    10        SEND_VAR                                                     $5
   14    11        DO_ICALL                                                     
   21    12      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3SiGo
function name:  {closure:/in/3SiGo:17}
number of ops:  25
compiled vars:  !0 = $result, !1 = $range, !2 = $array
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   17     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        BIND_STATIC                                                  !2
   18     3        INIT_FCALL                                                   'array_sum'
          4        INIT_FCALL                                                   'array_intersect_key'
          5        SEND_VAR                                                     !2
          6        INIT_FCALL                                                   'array_flip'
          7        INIT_FCALL                                                   'range'
          8        INIT_FCALL                                                   'sscanf'
          9        SEND_VAR                                                     !1
         10        SEND_VAL                                                     '%25d-%25d'
         11        DO_ICALL                                             $3      
         12        SEND_UNPACK                                                  $3
         13        CHECK_UNDEF_ARGS                                             
         14        DO_ICALL                                             $4      
         15        SEND_VAR                                                     $4
         16        DO_ICALL                                             $5      
         17        SEND_VAR                                                     $5
         18        DO_ICALL                                             $6      
         19        SEND_VAR                                                     $6
         20        DO_ICALL                                             $7      
         21        INIT_ARRAY                                           ~8      $7, !1
         22        ADD                                                  ~9      !0, ~8
         23      > RETURN                                                       ~9
         24*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
170.58 ms | 1496 KiB | 20 Q