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' => ['min' => 1, 'max' => 5], '6-10' => ['min' => 6, 'max' => 10], '1000-5000' => ['min' => 1000, 'max' => 5000], ]; $result = array_map(fn() => 0, $ranges); foreach ($array as $num => $amount) { foreach ($ranges as $rangeName => ['min' => $min, 'max' => $max]) { if ($num >= $min && $num <= $max) { $result[$rangeName] += $amount; break; } } } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 30
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 30
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 28
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 28
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 27
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 23
Branch analysis from position: 28
Branch analysis from position: 28
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/rGAZL
function name:  (null)
number of ops:  35
compiled vars:  !0 = $array, !1 = $ranges, !2 = $result, !3 = $amount, !4 = $num, !5 = $min, !6 = $max, !7 = $rangeName
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   12     1        ASSIGN                                                       !1, <array>
   18     2        INIT_FCALL                                                   'array_map'
          3        DECLARE_LAMBDA_FUNCTION                              ~10     [0]
          4        SEND_VAL                                                     ~10
          5        SEND_VAR                                                     !1
          6        DO_ICALL                                             $11     
          7        ASSIGN                                                       !2, $11
   19     8      > FE_RESET_R                                           $13     !0, ->30
          9    > > FE_FETCH_R                                           ~14     $13, !3, ->30
         10    >   ASSIGN                                                       !4, ~14
   20    11      > FE_RESET_R                                           $16     !1, ->28
         12    > > FE_FETCH_R                                           ~22     $16, $17, ->28
         13    >   FETCH_LIST_R                                         $18     $17, 'min'
         14        ASSIGN                                                       !5, $18
         15        FETCH_LIST_R                                         $20     $17, 'max'
         16        ASSIGN                                                       !6, $20
         17        FREE                                                         $17
         18        ASSIGN                                                       !7, ~22
   21    19        IS_SMALLER_OR_EQUAL                                  ~24     !5, !4
         20      > JMPZ_EX                                              ~24     ~24, ->23
         21    >   IS_SMALLER_OR_EQUAL                                  ~25     !4, !6
         22        BOOL                                                 ~24     ~25
         23    > > JMPZ                                                         ~24, ->27
   22    24    >   ASSIGN_DIM_OP                    +=               1          !2, !7
         25        OP_DATA                                                      !3
   23    26      > JMP                                                          ->28
   20    27    > > JMP                                                          ->12
         28    >   FE_FREE                                                      $16
   19    29      > JMP                                                          ->9
         30    >   FE_FREE                                                      $13
   27    31        INIT_FCALL                                                   'var_export'
         32        SEND_VAR                                                     !2
         33        DO_ICALL                                                     
         34      > 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/rGAZL
function name:  {closure:/in/rGAZL:18}
number of ops:  2
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E > > RETURN                                                       0
          1*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
155.77 ms | 1899 KiB | 15 Q