3v4l.org

run code in 300+ PHP versions simultaneously
<?php function map(array $array, array $keys) { $filter = function ($branch) { return $branch; }; foreach (array_reverse($keys) as $key) { $filter = function ($branch) use ($filter, $key) { switch ($key) { case '*': case '?': return array_map(function ($dimension) use ($filter) { return $filter($dimension); }, $branch); default: return $filter($branch)[$key]; } }; } return $filter($array); } $array = [ 'a' => [ 'b' => [ [ 'c' => 'foo', ], [ 'c' => 'bar', ], [ 'c' => 'qux', ], ], ], ]; $keys = ['a', 'b', '*', 'c']; var_dump(map($array, $keys));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Bm8aX
function name:  (null)
number of ops:  10
compiled vars:  !0 = $array, !1 = $keys
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ASSIGN                                                   !0, <array>
   42     1        ASSIGN                                                   !1, <array>
   44     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'map'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function map:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/Bm8aX
function name:  map
number of ops:  20
compiled vars:  !0 = $array, !1 = $keys, !2 = $filter, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBm8aX%3A5%240'
          3        ASSIGN                                                   !2, ~4
    8     4        INIT_FCALL                                               'array_reverse'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $6      
          7      > FE_RESET_R                                       $7      $6, ->14
          8    > > FE_FETCH_R                                               $7, !3, ->14
   10     9    >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBm8aX%3A10%241'
         10        BIND_LEXICAL                                             ~8, !2
         11        BIND_LEXICAL                                             ~8, !3
         12        ASSIGN                                                   !2, ~8
    8    13      > JMP                                                      ->8
         14    >   FE_FREE                                                  $7
   23    15        INIT_DYNAMIC_CALL                                        !2
         16        SEND_VAR_EX                                              !0
         17        DO_FCALL                                      0  $10     
         18      > RETURN                                                   $10
   24    19*     > RETURN                                                   null

End of function map

Function %00%7Bclosure%7D%2Fin%2FBm8aX%3A5%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Bm8aX
function name:  {closure}
number of ops:  3
compiled vars:  !0 = $branch
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1      > RETURN                                                   !0
    7     2*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBm8aX%3A5%240

Function %00%7Bclosure%7D%2Fin%2FBm8aX%3A10%241:
Finding entry points
Branch analysis from position: 0
4 jumps found. (Code = 188) Position 1 = 9, Position 2 = 9, Position 3 = 16, Position 4 = 4
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 9
Branch analysis from position: 9
filename:       /in/Bm8aX
function name:  {closure}
number of ops:  22
compiled vars:  !0 = $branch, !1 = $filter, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   11     3      > SWITCH_STRING                                            !2, [ '%2A':->9, '%3F':->9, ], ->16
   13     4    >   IS_EQUAL                                                 !2, '%2A'
          5      > JMPNZ                                                    ~3, ->9
   14     6    >   IS_EQUAL                                                 !2, '%3F'
          7      > JMPNZ                                                    ~3, ->9
          8    > > JMP                                                      ->16
   15     9    >   INIT_FCALL                                               'array_map'
         10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBm8aX%3A15%242'
         11        BIND_LEXICAL                                             ~4, !1
   17    12        SEND_VAL                                                 ~4
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $5      
         15      > RETURN                                                   $5
   19    16    >   INIT_DYNAMIC_CALL                                        !1
         17        SEND_VAR_EX                                              !0
         18        DO_FCALL                                      0  $6      
         19        FETCH_DIM_R                                      ~7      $6, !2
         20      > RETURN                                                   ~7
   21    21*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBm8aX%3A10%241

Function %00%7Bclosure%7D%2Fin%2FBm8aX%3A15%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Bm8aX
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $dimension, !1 = $filter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   16     2        INIT_DYNAMIC_CALL                                        !1
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5      > RETURN                                                   $2
   17     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBm8aX%3A15%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.94 ms | 1407 KiB | 20 Q