3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = array( 0 => 2, 1 => 3, 2 => 10, 3 => 3, 4 => 4, 5 => 8, 6 => 5, 7 => 1, 8 => 1 ); $b = array( 0 => "Hello world poduct", 1 => "Test Product", 2 => "Hello world poduct", 3 => "Hello world poduct", 4 => "Test Product", 5 => "Test Product", 6 => "Test Product", 7 => "Test Product", 8 => "Test Product", ); #foreach usage $result = []; $numbers = $a; $names = $b; foreach ($names as $index => $name) { $result[$name] ??= 0; $result[$name] += $numbers[$index]; } var_export($result, false); #for usage $result = []; for($i=0;$i<count($a);$i++){ if(!isset($result[$b[$i]])){ $result[$b[$i]] = 0; } $result[$b[$i]] += $a[$i]; } echo PHP_EOL; var_export($result); #array_walk $result = []; array_walk($a,function($v,$i) use (&$result,$b) { if(!isset($result[$b[$i]])){ $result[$b[$i]] = 0; } $result[$b[$i]] += $v; }); echo PHP_EOL; var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 18
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 18
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 26
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 33
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 26
Branch analysis from position: 41
Branch analysis from position: 26
Branch analysis from position: 33
Branch analysis from position: 18
filename:       /in/OeWln
function name:  (null)
number of ops:  58
compiled vars:  !0 = $a, !1 = $b, !2 = $result, !3 = $numbers, !4 = $names, !5 = $name, !6 = $index, !7 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   15     1        ASSIGN                                                   !1, <array>
   28     2        ASSIGN                                                   !2, <array>
   29     3        ASSIGN                                                   !3, !0
   30     4        ASSIGN                                                   !4, !1
   31     5      > FE_RESET_R                                       $13     !4, ->18
          6    > > FE_FETCH_R                                       ~14     $13, !5, ->18
          7    >   ASSIGN                                                   !6, ~14
   32     8        FETCH_DIM_IS                                     ~16     !2, !5
          9        COALESCE                                         ~17     ~16
         10        ASSIGN_DIM                                       ~18     !2, !5
         11        OP_DATA                                                  0
         12        QM_ASSIGN                                        ~17     ~18
         13        FREE                                                     ~17
   33    14        FETCH_DIM_R                                      ~20     !3, !6
         15        ASSIGN_DIM_OP                +=               1          !2, !5
         16        OP_DATA                                                  ~20
   31    17      > JMP                                                      ->6
         18    >   FE_FREE                                                  $13
   35    19        INIT_FCALL                                               'var_export'
         20        SEND_VAR                                                 !2
         21        SEND_VAL                                                 <false>
         22        DO_ICALL                                                 
   38    23        ASSIGN                                                   !2, <array>
   39    24        ASSIGN                                                   !7, 0
         25      > JMP                                                      ->38
   40    26    >   FETCH_DIM_R                                      ~24     !1, !7
         27        ISSET_ISEMPTY_DIM_OBJ                         0  ~25     !2, ~24
         28        BOOL_NOT                                         ~26     ~25
         29      > JMPZ                                                     ~26, ->33
   41    30    >   FETCH_DIM_R                                      ~27     !1, !7
         31        ASSIGN_DIM                                               !2, ~27
         32        OP_DATA                                                  0
   43    33    >   FETCH_DIM_R                                      ~29     !1, !7
         34        FETCH_DIM_R                                      ~31     !0, !7
         35        ASSIGN_DIM_OP                +=               1          !2, ~29
         36        OP_DATA                                                  ~31
   39    37        PRE_INC                                                  !7
         38    >   COUNT                                            ~33     !0
         39        IS_SMALLER                                               !7, ~33
         40      > JMPNZ                                                    ~34, ->26
   45    41    >   ECHO                                                     '%0A'
   46    42        INIT_FCALL                                               'var_export'
         43        SEND_VAR                                                 !2
         44        DO_ICALL                                                 
   49    45        ASSIGN                                                   !2, <array>
   50    46        INIT_FCALL                                               'array_walk'
         47        SEND_REF                                                 !0
         48        DECLARE_LAMBDA_FUNCTION                          ~37     [0]
         49        BIND_LEXICAL                                             ~37, !2
         50        BIND_LEXICAL                                             ~37, !1
   55    51        SEND_VAL                                                 ~37
   50    52        DO_ICALL                                                 
   56    53        ECHO                                                     '%0A'
   57    54        INIT_FCALL                                               'var_export'
         55        SEND_VAR                                                 !2
         56        DO_ICALL                                                 
         57      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/OeWln
function name:  {closure}
number of ops:  15
compiled vars:  !0 = $v, !1 = $i, !2 = $result, !3 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
          3        BIND_STATIC                                              !3
   51     4        FETCH_DIM_R                                      ~4      !3, !1
          5        ISSET_ISEMPTY_DIM_OBJ                         0  ~5      !2, ~4
          6        BOOL_NOT                                         ~6      ~5
          7      > JMPZ                                                     ~6, ->11
   52     8    >   FETCH_DIM_R                                      ~7      !3, !1
          9        ASSIGN_DIM                                               !2, ~7
         10        OP_DATA                                                  0
   54    11    >   FETCH_DIM_R                                      ~9      !3, !1
         12        ASSIGN_DIM_OP                +=               1          !2, ~9
         13        OP_DATA                                                  !0
   55    14      > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.69 ms | 1008 KiB | 15 Q