3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getArrayFromHyphenArray($flatArray){ $deepArray = array(); foreach($flatArray as $key => $value){ $keysArray = explode('-', $key); $deepArray = recursiveSet($deepArray, $keysArray, $value); } } function recursiveSet(&$array, &$arg, $value){ static $count = 0; if(empty($arg)){ $array = $value; return $array; } $key = array_shift($arg); if(!isset($array[$key])){ print_r($key); $count++; echo $count; $array[$key] = array(); } return recursiveSet($array[$key],$arg,$value); } $flatArray = array('this-is-something' => 'value1', 'bif-is-else' => 'value3', 'this-different-else' => 'value2'); print_r(getArrayFromHyphenArray($flatArray));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/v2iiH
function name:  (null)
number of ops:  8
compiled vars:  !0 = $flatArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   ASSIGN                                                   !0, <array>
   27     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'getarrayfromhyphenarray'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function getarrayfromhyphenarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 17
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/v2iiH
function name:  getArrayFromHyphenArray
number of ops:  19
compiled vars:  !0 = $flatArray, !1 = $deepArray, !2 = $value, !3 = $key, !4 = $keysArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        ASSIGN                                                   !1, <array>
    4     2      > FE_RESET_R                                       $6      !0, ->17
          3    > > FE_FETCH_R                                       ~7      $6, !2, ->17
          4    >   ASSIGN                                                   !3, ~7
    5     5        INIT_FCALL                                               'explode'
          6        SEND_VAL                                                 '-'
          7        SEND_VAR                                                 !3
          8        DO_ICALL                                         $9      
          9        ASSIGN                                                   !4, $9
    6    10        INIT_FCALL_BY_NAME                                       'recursiveSet'
         11        SEND_VAR_EX                                              !1
         12        SEND_VAR_EX                                              !4
         13        SEND_VAR_EX                                              !2
         14        DO_FCALL                                      0  $11     
         15        ASSIGN                                                   !1, $11
    4    16      > JMP                                                      ->3
         17    >   FE_FREE                                                  $6
    8    18      > RETURN                                                   null

End of function getarrayfromhyphenarray

Function recursiveset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/v2iiH
function name:  recursiveSet
number of ops:  31
compiled vars:  !0 = $array, !1 = $arg, !2 = $value, !3 = $count, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   10     3        BIND_STATIC                                              !3
   12     4        ISSET_ISEMPTY_CV                                         !1
          5      > JMPZ                                                     ~5, ->8
   13     6    >   ASSIGN                                                   !0, !2
   14     7      > RETURN                                                   !0
   16     8    >   INIT_FCALL                                               'array_shift'
          9        SEND_REF                                                 !1
         10        DO_ICALL                                         $7      
         11        ASSIGN                                                   !4, $7
   17    12        ISSET_ISEMPTY_DIM_OBJ                         0  ~9      !0, !4
         13        BOOL_NOT                                         ~10     ~9
         14      > JMPZ                                                     ~10, ->22
   18    15    >   INIT_FCALL                                               'print_r'
         16        SEND_VAR                                                 !4
         17        DO_ICALL                                                 
   19    18        PRE_INC                                                  !3
   20    19        ECHO                                                     !3
   21    20        ASSIGN_DIM                                               !0, !4
         21        OP_DATA                                                  <array>
   23    22    >   INIT_FCALL_BY_NAME                                       'recursiveSet'
         23        CHECK_FUNC_ARG                                           
         24        FETCH_DIM_FUNC_ARG                               $14     !0, !4
         25        SEND_FUNC_ARG                                            $14
         26        SEND_VAR_EX                                              !1
         27        SEND_VAR_EX                                              !2
         28        DO_FCALL                                      0  $15     
         29      > RETURN                                                   $15
   24    30*     > RETURN                                                   null

End of function recursiveset

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.66 ms | 1403 KiB | 20 Q