3v4l.org

run code in 500+ PHP versions simultaneously
<?php class FlattenArray { private array $mapped = []; public function __construct(array $input) { $this->mapped = array_map(fn ($currentKey) => $this->mapRecursive(explode('_', $currentKey), $input[$currentKey]), array_keys($input)); } private function mapRecursive(array $keys, $value) { if (empty($keys)) return; return array_fill_keys( [array_shift($keys)], $this->mapRecursive($keys, $value) ?? $value ); } public function joinAndFlatten() { return $this->mapped; } } var_dump((new FlattenArray(['a_a' => '2', 'a_b' => '333', 'c_c' => '123']))->joinAndFlatten());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oYJH5
function name:  (null)
number of ops:  9
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   29     0  E >   INIT_FCALL                                                   'var_dump'
          1        NEW                                                  $0      'FlattenArray'
          2        SEND_VAL_EX                                                  <array>
          3        DO_FCALL                                          0          
          4        INIT_METHOD_CALL                                             $0, 'joinAndFlatten'
          5        DO_FCALL                                          0  $2      
          6        SEND_VAR                                                     $2
          7        DO_ICALL                                                     
          8      > RETURN                                                       1

Class FlattenArray:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oYJH5
function name:  __construct
number of ops:  13
compiled vars:  !0 = $input
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
    9     1        INIT_FCALL                                                   'array_map'
          2        DECLARE_LAMBDA_FUNCTION                              ~2      [0]
          3        BIND_LEXICAL                                                 ~2, !0
          4        SEND_VAL                                                     ~2
          5        INIT_FCALL                                                   'array_keys'
          6        SEND_VAR                                                     !0
          7        DO_ICALL                                             $3      
          8        SEND_VAR                                                     $3
          9        DO_ICALL                                             $4      
         10        ASSIGN_OBJ                                                   'mapped'
         11        OP_DATA                                                      $4
   10    12      > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oYJH5
function name:  {closure:FlattenArray::__construct():9}
number of ops:  14
compiled vars:  !0 = $currentKey, !1 = $input
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
          2        INIT_METHOD_CALL                                             'mapRecursive'
          3        INIT_FCALL                                                   'explode'
          4        SEND_VAL                                                     '_'
          5        SEND_VAR                                                     !0
          6        DO_ICALL                                             $2      
          7        SEND_VAR_NO_REF_EX                                           $2
          8        CHECK_FUNC_ARG                                               
          9        FETCH_DIM_FUNC_ARG                                   $3      !1, !0
         10        SEND_FUNC_ARG                                                $3
         11        DO_FCALL                                          0  $4      
         12      > RETURN                                                       $4
         13*     > RETURN                                                       null

End of Dynamic Function 0

End of function __construct

Function maprecursive:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oYJH5
function name:  mapRecursive
number of ops:  21
compiled vars:  !0 = $keys, !1 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   12     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   14     2        ISSET_ISEMPTY_CV                                             !0
          3      > JMPZ                                                         ~2, ->5
          4    > > RETURN                                                       null
   16     5    >   INIT_FCALL                                                   'array_fill_keys'
   17     6        INIT_FCALL                                                   'array_shift'
          7        SEND_REF                                                     !0
          8        DO_ICALL                                             $3      
          9        INIT_ARRAY                                           ~4      $3
         10        SEND_VAL                                                     ~4
         11        INIT_METHOD_CALL                                             'mapRecursive'
         12        SEND_VAR                                                     !0
         13        SEND_VAR                                                     !1
         14        DO_FCALL                                          0  $5      
         15        COALESCE                                             ~6      $5
         16        QM_ASSIGN                                            ~6      !1
         17        SEND_VAL                                                     ~6
   16    18        DO_ICALL                                             $7      
   17    19      > RETURN                                                       $7
   19    20*     > RETURN                                                       null

End of function maprecursive

Function joinandflatten:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oYJH5
function name:  joinAndFlatten
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   23     0  E >   FETCH_OBJ_R                                          ~0      'mapped'
          1      > RETURN                                                       ~0
   24     2*     > RETURN                                                       null

End of function joinandflatten

End of class FlattenArray.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
173.26 ms | 1492 KiB | 19 Q