3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public function bar($tags, $product_row) { $path_arr = []; foreach ($product_row['fields'] as $field) { //gets the path for this field like pathto/field $strpath = $tags[$field['id']]['str_path']; $paths = explode('/', $strpath); $this->stringKeyToMultArray($path_arr, $paths, $field['value']); } return json_encode($path_arr, JSON_PRETTY_PRINT); } protected function stringKeyToMultArray(&$newarr, $keys, $value) { if (count($keys) > 1) { $key = array_shift($keys); if ( !isset($newarr[$key]) || !is_array($newarr[$key])) { $newarr[$key] = array(array()); } $this->stringKeyToMultArray($newarr[$key][0], $keys, $value); } else { $newarr[array_shift($keys)] = $value; } } } $foo = new Foo; $tags = array( 1 => array('str_path' => 'product_title'), 2 => array('str_path' => 'ASIN'), 3 => array('str_path' => 'codes/type'), 4 => array('str_path' => 'codes/number'), 5 => array('str_path' => 'quantity') ); $product_row = array('fields' => array( array('id' => 1, 'value' => 'Test Title'), array('id' => 2, 'value' => '1234567890'), array('id' => 3, 'value' => 'UPC'), array('id' => 4, 'value' => '030878249270'), array('id' => 3, 'value' => 'UPC'), )); echo $foo->bar($tags, $product_row);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4Hpek
function name:  (null)
number of ops:  11
compiled vars:  !0 = $foo, !1 = $tags, !2 = $product_row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   NEW                                              $3      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
   32     3        ASSIGN                                                   !1, <array>
   39     4        ASSIGN                                                   !2, <array>
   47     5        INIT_METHOD_CALL                                         !0, 'bar'
          6        SEND_VAR_EX                                              !1
          7        SEND_VAR_EX                                              !2
          8        DO_FCALL                                      0  $8      
          9        ECHO                                                     $8
         10      > RETURN                                                   1

Class Foo:
Function bar:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 23
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 23
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/4Hpek
function name:  bar
number of ops:  30
compiled vars:  !0 = $tags, !1 = $product_row, !2 = $path_arr, !3 = $field, !4 = $strpath, !5 = $paths
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        ASSIGN                                                   !2, <array>
    7     3        FETCH_DIM_R                                      ~7      !1, 'fields'
          4      > FE_RESET_R                                       $8      ~7, ->23
          5    > > FE_FETCH_R                                               $8, !3, ->23
    9     6    >   FETCH_DIM_R                                      ~9      !3, 'id'
          7        FETCH_DIM_R                                      ~10     !0, ~9
          8        FETCH_DIM_R                                      ~11     ~10, 'str_path'
          9        ASSIGN                                                   !4, ~11
   10    10        INIT_FCALL                                               'explode'
         11        SEND_VAL                                                 '%2F'
         12        SEND_VAR                                                 !4
         13        DO_ICALL                                         $13     
         14        ASSIGN                                                   !5, $13
   11    15        INIT_METHOD_CALL                                         'stringKeyToMultArray'
         16        SEND_VAR_EX                                              !2
         17        SEND_VAR_EX                                              !5
         18        CHECK_FUNC_ARG                                           
         19        FETCH_DIM_FUNC_ARG                               $15     !3, 'value'
         20        SEND_FUNC_ARG                                            $15
         21        DO_FCALL                                      0          
    7    22      > JMP                                                      ->5
         23    >   FE_FREE                                                  $8
   13    24        INIT_FCALL                                               'json_encode'
         25        SEND_VAR                                                 !2
         26        SEND_VAL                                                 128
         27        DO_ICALL                                         $17     
         28      > RETURN                                                   $17
   14    29*     > RETURN                                                   null

End of function bar

Function stringkeytomultarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 29
Branch analysis from position: 6
2 jumps found. (Code = 47) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 17
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4Hpek
function name:  stringKeyToMultArray
number of ops:  35
compiled vars:  !0 = $newarr, !1 = $keys, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   17     3        COUNT                                            ~4      !1
          4        IS_SMALLER                                               1, ~4
          5      > JMPZ                                                     ~5, ->29
   18     6    >   INIT_FCALL                                               'array_shift'
          7        SEND_REF                                                 !1
          8        DO_ICALL                                         $6      
          9        ASSIGN                                                   !3, $6
   19    10        ISSET_ISEMPTY_DIM_OBJ                         0  ~8      !0, !3
         11        BOOL_NOT                                         ~9      ~8
         12      > JMPNZ_EX                                         ~9      ~9, ->17
         13    >   FETCH_DIM_R                                      ~10     !0, !3
         14        TYPE_CHECK                                  128  ~11     ~10
         15        BOOL_NOT                                         ~12     ~11
         16        BOOL                                             ~9      ~12
         17    > > JMPZ                                                     ~9, ->20
   20    18    >   ASSIGN_DIM                                               !0, !3
         19        OP_DATA                                                  <array>
   22    20    >   INIT_METHOD_CALL                                         'stringKeyToMultArray'
         21        CHECK_FUNC_ARG                                           
         22        FETCH_DIM_FUNC_ARG                               $14     !0, !3
         23        FETCH_DIM_FUNC_ARG                               $15     $14, 0
         24        SEND_FUNC_ARG                                            $15
         25        SEND_VAR_EX                                              !1
         26        SEND_VAR_EX                                              !2
         27        DO_FCALL                                      0          
   17    28      > JMP                                                      ->34
   25    29    >   INIT_FCALL                                               'array_shift'
         30        SEND_REF                                                 !1
         31        DO_ICALL                                         $17     
         32        ASSIGN_DIM                                               !0, $17
         33        OP_DATA                                                  !2
   27    34    > > RETURN                                                   null

End of function stringkeytomultarray

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.18 ms | 1021 KiB | 16 Q