3v4l.org

run code in 300+ PHP versions simultaneously
<?php $second_names = ['Cars', 'Bikes', 'Trucks']; $premiumCatArraySets = [ [ 'primary-category' => 'Automobiles', 'secondary-category' => 'Cars', 'tertiary-category' => 'Fiat Punto' ], [ 'primary-category' => 'Automobiles', 'secondary-category' => 'Cars', 'tertiary-category' => 'BMW' ], [ 'primary-category' => 'Automobiles', 'secondary-category' => 'Bikes', 'tertiary-category' => 'Honda' ], [ 'primary-category' => 'Automobiles', 'secondary-category' => 'Trucks', 'tertiary-category' => 'Iveco' ] , [ 'primary-category' => 'Automobiles', 'secondary-category' => 'Cars', 'tertiary-category' => 'Mercedes' ] , [ 'primary-category' => 'Automobiles', 'secondary-category' => 'Cars', 'tertiary-category' => 'Toyota' ] ]; $output = []; foreach($premiumCatArraySets as $key => $value){ if(in_array($value["secondary-category"],$second_names)){ if(!isset($output[$value["secondary-category"]])){ $output[$value["secondary-category"]] = []; } $output[$value["secondary-category"]][] = $value["tertiary-category"]; } } foreach($output as $key => $value){ echo '<h2>'.$key."</h2>"; echo implode(",",$value)."<br/>"; } print_r($output);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 25
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 25
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 24
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 19
Branch analysis from position: 24
Branch analysis from position: 25
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 39
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 39
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
Branch analysis from position: 25
filename:       /in/5RnUC
function name:  (null)
number of ops:  44
compiled vars:  !0 = $second_names, !1 = $premiumCatArraySets, !2 = $output, !3 = $value, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
   39     2        ASSIGN                                                   !2, <array>
   40     3      > FE_RESET_R                                       $8      !1, ->25
          4    > > FE_FETCH_R                                       ~9      $8, !3, ->25
          5    >   ASSIGN                                                   !4, ~9
   41     6        INIT_FCALL                                               'in_array'
          7        FETCH_DIM_R                                      ~11     !3, 'secondary-category'
          8        SEND_VAL                                                 ~11
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $12     
         11      > JMPZ                                                     $12, ->24
   42    12    >   FETCH_DIM_R                                      ~13     !3, 'secondary-category'
         13        ISSET_ISEMPTY_DIM_OBJ                         0  ~14     !2, ~13
         14        BOOL_NOT                                         ~15     ~14
         15      > JMPZ                                                     ~15, ->19
   43    16    >   FETCH_DIM_R                                      ~16     !3, 'secondary-category'
         17        ASSIGN_DIM                                               !2, ~16
         18        OP_DATA                                                  <array>
   45    19    >   FETCH_DIM_R                                      ~18     !3, 'secondary-category'
         20        FETCH_DIM_R                                      ~21     !3, 'tertiary-category'
         21        FETCH_DIM_W                                      $19     !2, ~18
         22        ASSIGN_DIM                                               $19
         23        OP_DATA                                                  ~21
   40    24    > > JMP                                                      ->4
         25    >   FE_FREE                                                  $8
   48    26      > FE_RESET_R                                       $22     !2, ->39
         27    > > FE_FETCH_R                                       ~23     $22, !3, ->39
         28    >   ASSIGN                                                   !4, ~23
   49    29        CONCAT                                           ~25     '%3Ch2%3E', !4
         30        CONCAT                                           ~26     ~25, '%3C%2Fh2%3E'
         31        ECHO                                                     ~26
   50    32        INIT_FCALL                                               'implode'
         33        SEND_VAL                                                 '%2C'
         34        SEND_VAR                                                 !3
         35        DO_ICALL                                         $27     
         36        CONCAT                                           ~28     $27, '%3Cbr%2F%3E'
         37        ECHO                                                     ~28
   48    38      > JMP                                                      ->27
         39    >   FE_FREE                                                  $22
   53    40        INIT_FCALL                                               'print_r'
         41        SEND_VAR                                                 !2
         42        DO_ICALL                                                 
         43      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.36 ms | 1005 KiB | 16 Q