3v4l.org

run code in 300+ PHP versions simultaneously
<?php $items = array( array("itemName" => "Hat", "price" => 10.99, "categories" => ["apparel", "head"]), array("itemName" => "Scarf", "price" => 7.99, "categories" => ["apparel", "neck"]), array("itemName" => "Watch", "price" => 19.99, "categories" => ["jewelry", "electronics"]), array("itemName" => "Necklace", "price" => 99.99, "categories" => ["jewelry", "neck"]), array("itemName" => "Headphones", "price" => 29.99, "categories" => ["head", "electronics"]) ); foreach (array_unique(array_merge(...array_values(array_column($items, 'categories')))) as $value) { foreach ($items as $item) { if (in_array($value, $item['categories'])) { $categories[$value][] = $item['itemName']; } } } print_r($categories);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 32
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 32
Branch analysis from position: 17
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 30
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 30
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 29
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 30
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/Qag3c
function name:  (null)
number of ops:  37
compiled vars:  !0 = $items, !1 = $value, !2 = $item, !3 = $categories
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   11     1        INIT_FCALL                                               'array_unique'
          2        INIT_FCALL                                               'array_merge'
          3        INIT_FCALL                                               'array_values'
          4        INIT_FCALL                                               'array_column'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 'categories'
          7        DO_ICALL                                         $5      
          8        SEND_VAR                                                 $5
          9        DO_ICALL                                         $6      
         10        SEND_UNPACK                                              $6
         11        CHECK_UNDEF_ARGS                                         
         12        DO_ICALL                                         $7      
         13        SEND_VAR                                                 $7
         14        DO_ICALL                                         $8      
         15      > FE_RESET_R                                       $9      $8, ->32
         16    > > FE_FETCH_R                                               $9, !1, ->32
   12    17    > > FE_RESET_R                                       $10     !0, ->30
         18    > > FE_FETCH_R                                               $10, !2, ->30
   13    19    >   INIT_FCALL                                               'in_array'
         20        SEND_VAR                                                 !1
         21        FETCH_DIM_R                                      ~11     !2, 'categories'
         22        SEND_VAL                                                 ~11
         23        DO_ICALL                                         $12     
         24      > JMPZ                                                     $12, ->29
   14    25    >   FETCH_DIM_R                                      ~15     !2, 'itemName'
         26        FETCH_DIM_W                                      $13     !3, !1
         27        ASSIGN_DIM                                               $13
         28        OP_DATA                                                  ~15
   12    29    > > JMP                                                      ->18
         30    >   FE_FREE                                                  $10
   11    31      > JMP                                                      ->16
         32    >   FE_FREE                                                  $9
   19    33        INIT_FCALL                                               'print_r'
         34        SEND_VAR                                                 !3
         35        DO_ICALL                                                 
         36      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.03 ms | 1015 KiB | 19 Q