3v4l.org

run code in 300+ PHP versions simultaneously
<?php $items = []; for ($i = 0; $i < 3000; $i++) { $items[] = [ 'foo' => 1, 'qty' => ($i%7)+1, 'bar' => 2, 'weight' => ($i%2)+1, 'baz' => 3, ]; } $start =microtime(1); $weights =array_unique(array_column($items, 'weight')); $result =[]; Foreach($weights as $weight){ $weightitems = array_filter($items, function ($var) use ($weight) { return ($var['weight'] == $weight); }); $result[] = array_sum(array_column($weightitems, "qty")) * $weight; } Echo array_sum($result) ."\n"; Echo (microtime(1)-$start)*100;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 3
Branch analysis from position: 17
2 jumps found. (Code = 77) Position 1 = 31, Position 2 = 50
Branch analysis from position: 31
2 jumps found. (Code = 78) Position 1 = 32, Position 2 = 50
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 3
Branch analysis from position: 17
Branch analysis from position: 3
filename:       /in/aB7d9
function name:  (null)
number of ops:  63
compiled vars:  !0 = $items, !1 = $i, !2 = $start, !3 = $weights, !4 = $result, !5 = $weight, !6 = $weightitems
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->15
    6     3    >   INIT_ARRAY                                       ~10     1, 'foo'
    7     4        MOD                                              ~11     !1, 7
          5        ADD                                              ~12     ~11, 1
          6        ADD_ARRAY_ELEMENT                                ~10     ~12, 'qty'
    8     7        ADD_ARRAY_ELEMENT                                ~10     2, 'bar'
    9     8        MOD                                              ~13     !1, 2
          9        ADD                                              ~14     ~13, 1
         10        ADD_ARRAY_ELEMENT                                ~10     ~14, 'weight'
   10    11        ADD_ARRAY_ELEMENT                                ~10     3, 'baz'
    5    12        ASSIGN_DIM                                               !0
   10    13        OP_DATA                                                  ~10
    4    14        PRE_INC                                                  !1
         15    >   IS_SMALLER                                               !1, 3000
         16      > JMPNZ                                                    ~16, ->3
   14    17    >   INIT_FCALL                                               'microtime'
         18        SEND_VAL                                                 1
         19        DO_ICALL                                         $17     
         20        ASSIGN                                                   !2, $17
   15    21        INIT_FCALL                                               'array_unique'
         22        INIT_FCALL                                               'array_column'
         23        SEND_VAR                                                 !0
         24        SEND_VAL                                                 'weight'
         25        DO_ICALL                                         $19     
         26        SEND_VAR                                                 $19
         27        DO_ICALL                                         $20     
         28        ASSIGN                                                   !3, $20
   16    29        ASSIGN                                                   !4, <array>
   17    30      > FE_RESET_R                                       $23     !3, ->50
         31    > > FE_FETCH_R                                               $23, !5, ->50
   18    32    >   INIT_FCALL                                               'array_filter'
         33        SEND_VAR                                                 !0
         34        DECLARE_LAMBDA_FUNCTION                          ~24     [0]
         35        BIND_LEXICAL                                             ~24, !5
   20    36        SEND_VAL                                                 ~24
   18    37        DO_ICALL                                         $25     
         38        ASSIGN                                                   !6, $25
   21    39        INIT_FCALL                                               'array_sum'
         40        INIT_FCALL                                               'array_column'
         41        SEND_VAR                                                 !6
         42        SEND_VAL                                                 'qty'
         43        DO_ICALL                                         $28     
         44        SEND_VAR                                                 $28
         45        DO_ICALL                                         $29     
         46        MUL                                              ~30     !5, $29
         47        ASSIGN_DIM                                               !4
         48        OP_DATA                                                  ~30
   17    49      > JMP                                                      ->31
         50    >   FE_FREE                                                  $23
   23    51        INIT_FCALL                                               'array_sum'
         52        SEND_VAR                                                 !4
         53        DO_ICALL                                         $31     
         54        CONCAT                                           ~32     $31, '%0A'
         55        ECHO                                                     ~32
   24    56        INIT_FCALL                                               'microtime'
         57        SEND_VAL                                                 1
         58        DO_ICALL                                         $33     
         59        SUB                                              ~34     $33, !2
         60        MUL                                              ~35     ~34, 100
         61        ECHO                                                     ~35
   25    62      > 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/aB7d9
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $var, !1 = $weight
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   19     2        FETCH_DIM_R                                      ~2      !0, 'weight'
          3        IS_EQUAL                                         ~3      !1, ~2
          4      > RETURN                                                   ~3
   20     5*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.96 ms | 1009 KiB | 18 Q