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

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
133.86 ms | 1490 KiB | 14 Q