3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getArrayFromHyphenArray($flatArray){ $deepArray = array(); foreach($flatArray as $key => $value){ $keysArray = explode('-', $key); $deepArray = $this->recursiveSet($deepArray, $keysArray, $value); } } function recursiveSet(&$array, $arg, $value){ if(empty($arg)){ $array = $value; return $array; } $key = array_shift($arg); if(!isset($array[$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/OvlV0
function name:  (null)
number of ops:  8
compiled vars:  !0 = $arra
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                   !0, <array>
   22     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 = 18
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 18
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/OvlV0
function name:  getArrayFromHyphenArray
number of ops:  20
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, ->18
          3    > > FE_FETCH_R                                       ~7      $6, !2, ->18
          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        FETCH_THIS                                       $11     
         11        INIT_METHOD_CALL                                         $11, 'recursiveSet'
         12        SEND_VAR_EX                                              !1
         13        SEND_VAR_EX                                              !4
         14        SEND_VAR_EX                                              !2
         15        DO_FCALL                                      0  $12     
         16        ASSIGN                                                   !1, $12
    4    17      > JMP                                                      ->3
         18    >   FE_FREE                                                  $6
    8    19      > 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 = 16
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/OvlV0
function name:  recursiveSet
number of ops:  25
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, ->16
   16    14    >   ASSIGN_DIM                                               !0, !3
         15        OP_DATA                                                  <array>
   18    16    >   INIT_FCALL_BY_NAME                                       'recursiveSet'
         17        CHECK_FUNC_ARG                                           
         18        FETCH_DIM_FUNC_ARG                               $11     !0, !3
         19        SEND_FUNC_ARG                                            $11
         20        SEND_VAR_EX                                              !1
         21        SEND_VAR_EX                                              !2
         22        DO_FCALL                                      0  $12     
         23      > RETURN                                                   $12
   19    24*     > RETURN                                                   null

End of function recursiveset

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.64 ms | 1403 KiB | 20 Q