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){ if(empty($arg)){ $array = $value; return $array; } $key = array_shift($arg); if(!isset($array[$key])){ var_dump($key); $array[$key] = array(); } return recursiveSet($array[$key],$arg,$value); } $arra = array('this-is-some' => 'value', 'this-is-second' => 'value'); print_r(getArrayFromHyphenArray($arra));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JppQn
function name:  (null)
number of ops:  8
compiled vars:  !0 = $arra
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   ASSIGN                                                   !0, <array>
   23     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/JppQn
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 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/JppQn
function name:  recursiveSet
number of ops:  28
compiled vars:  !0 = $array, !1 = $arg, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   10     3        ISSET_ISEMPTY_CV                                         !1
          4      > JMPZ                                                     ~4, ->7
   11     5    >   ASSIGN                                                   !0, !2
   12     6      > RETURN                                                   !0
   14     7    >   INIT_FCALL                                               'array_shift'
          8        SEND_REF                                                 !1
          9        DO_ICALL                                         $6      
         10        ASSIGN                                                   !3, $6
   15    11        ISSET_ISEMPTY_DIM_OBJ                         0  ~8      !0, !3
         12        BOOL_NOT                                         ~9      ~8
         13      > JMPZ                                                     ~9, ->19
   16    14    >   INIT_FCALL                                               'var_dump'
         15        SEND_VAR                                                 !3
         16        DO_ICALL                                                 
   17    17        ASSIGN_DIM                                               !0, !3
         18        OP_DATA                                                  <array>
   19    19    >   INIT_FCALL_BY_NAME                                       'recursiveSet'
         20        CHECK_FUNC_ARG                                           
         21        FETCH_DIM_FUNC_ARG                               $12     !0, !3
         22        SEND_FUNC_ARG                                            $12
         23        SEND_VAR_EX                                              !1
         24        SEND_VAR_EX                                              !2
         25        DO_FCALL                                      0  $13     
         26      > RETURN                                                   $13
   20    27*     > RETURN                                                   null

End of function recursiveset

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
191.16 ms | 1403 KiB | 22 Q