3v4l.org

run code in 300+ PHP versions simultaneously
<?php $sortInfo = [ ['maincat' => 'c1', 'subcats' => ['sc1.1', 'sc1.2']], ['maincat' => 'c2', 'subcats' => ['sc2.1', 'sc2.2']], ['maincat' => 'c3', 'subcats' => ['sc3.1', 'sc3.2']], ['maincat' => 'c4', 'subcats' => ['sc4.1', 'sc4.2']], ['maincat' => 'c5', 'subcats' => ['sc5.1', 'sc5.2']], ]; function get_cats(array $sortInfo, $mode) { $cats = match($mode) { 'all' => array_merge( array_column($sortInfo, 'maincat'), ...array_column($sortInfo, 'subcats') ), 'sub' => array_merge(...array_column($sortInfo, 'subcats')), default => array_column($sortInfo, 'maincat') }; return $cats; } $cats = get_cats($sortInfo, 'all'); var_dump($cats); $cats = get_cats($sortInfo, 'sub'); var_dump($cats); $cats = get_cats($sortInfo, 'main'); var_dump($cats);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NasiC
function name:  (null)
number of ops:  26
compiled vars:  !0 = $sortInfo, !1 = $cats
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
   23     1        INIT_FCALL                                               'get_cats'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'all'
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !1, $3
   24     6        INIT_FCALL                                               'var_dump'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                                 
   26     9        INIT_FCALL                                               'get_cats'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 'sub'
         12        DO_FCALL                                      0  $6      
         13        ASSIGN                                                   !1, $6
   27    14        INIT_FCALL                                               'var_dump'
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                                 
   29    17        INIT_FCALL                                               'get_cats'
         18        SEND_VAR                                                 !0
         19        SEND_VAL                                                 'main'
         20        DO_FCALL                                      0  $9      
         21        ASSIGN                                                   !1, $9
   30    22        INIT_FCALL                                               'var_dump'
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                                 
         25      > RETURN                                                   1

Function get_cats:
Finding entry points
Branch analysis from position: 0
3 jumps found. (Code = 195) Position 1 = 3, Position 2 = 18, Position 3 = 28
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
filename:       /in/NasiC
function name:  get_cats
number of ops:  37
compiled vars:  !0 = $sortInfo, !1 = $mode, !2 = $cats
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2      > MATCH                                                    !1, [ 'all':->3, 'sub':->18, ], ->28
   14     3    >   INIT_FCALL                                               'array_merge'
   15     4        INIT_FCALL                                               'array_column'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 'maincat'
          7        DO_ICALL                                         $4      
          8        SEND_VAR                                                 $4
          9        INIT_FCALL                                               'array_column'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 'subcats'
         12        DO_ICALL                                         $5      
         13        SEND_UNPACK                                              $5
         14        CHECK_UNDEF_ARGS                                         
   14    15        DO_ICALL                                         $6      
   15    16        QM_ASSIGN                                        ~7      $6
         17      > JMP                                                      ->34
   17    18    >   INIT_FCALL                                               'array_merge'
         19        INIT_FCALL                                               'array_column'
         20        SEND_VAR                                                 !0
         21        SEND_VAL                                                 'subcats'
         22        DO_ICALL                                         $8      
         23        SEND_UNPACK                                              $8
         24        CHECK_UNDEF_ARGS                                         
         25        DO_ICALL                                         $9      
         26        QM_ASSIGN                                        ~7      $9
         27      > JMP                                                      ->34
   18    28    >   INIT_FCALL                                               'array_column'
         29        SEND_VAR                                                 !0
         30        SEND_VAL                                                 'maincat'
         31        DO_ICALL                                         $10     
         32        QM_ASSIGN                                        ~7      $10
         33      > JMP                                                      ->34
   13    34    >   ASSIGN                                                   !2, ~7
   20    35      > RETURN                                                   !2
   21    36*     > RETURN                                                   null

End of function get_cats

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.88 ms | 1007 KiB | 19 Q