3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = json_decode('{"1":{"id":"1","source_name":"kk56ca1d0f2378f","company_id":"1","lft":"1","rgt":"18","parent_id":"0","children":{"2":{"id":"2","source_name":"kk56ca1d17f3f63","company_id":"1","lft":"2","rgt":"3","parent_id":"1","children":[]},"3":{"id":"3","source_name":"kk56ca1d1ebe975","company_id":"1","lft":"4","rgt":"13","parent_id":"1","children":{"6":{"id":"6","source_name":"kk56ca1fc882ac0","company_id":"1","lft":"5","rgt":"10","parent_id":"3","children":[]}}}}}}',1); function convert_array( $array ) { $retval = array(); foreach( $array as $row ) { $child = array(); $child['id'] = $row['id']; $child['text'] = $row['source_name']; $child['parent_id'] = $row['parent_id']; if( count( $row['children'] ) ) { $child['nodes'] = convert_array( $row['children'] ); } else { $child['nodes'] = array(); } $retval[] = $child; } return $retval; } $result = convert_array( $array ); print_r( $result );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6LTk1
function name:  (null)
number of ops:  13
compiled vars:  !0 = $array, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'json_decode'
          1        SEND_VAL                                                 '%7B%221%22%3A%7B%22id%22%3A%221%22%2C%22source_name%22%3A%22kk56ca1d0f2378f%22%2C%22company_id%22%3A%221%22%2C%22lft%22%3A%221%22%2C%22rgt%22%3A%2218%22%2C%22parent_id%22%3A%220%22%2C%22children%22%3A%7B%222%22%3A%7B%22id%22%3A%222%22%2C%22source_name%22%3A%22kk56ca1d17f3f63%22%2C%22company_id%22%3A%221%22%2C%22lft%22%3A%222%22%2C%22rgt%22%3A%223%22%2C%22parent_id%22%3A%221%22%2C%22children%22%3A%5B%5D%7D%2C%223%22%3A%7B%22id%22%3A%223%22%2C%22source_name%22%3A%22kk56ca1d1ebe975%22%2C%22company_id%22%3A%221%22%2C%22lft%22%3A%224%22%2C%22rgt%22%3A%2213%22%2C%22parent_id%22%3A%221%22%2C%22children%22%3A%7B%226%22%3A%7B%22id%22%3A%226%22%2C%22source_name%22%3A%22kk56ca1fc882ac0%22%2C%22company_id%22%3A%221%22%2C%22lft%22%3A%225%22%2C%22rgt%22%3A%2210%22%2C%22parent_id%22%3A%223%22%2C%22children%22%3A%5B%5D%7D%7D%7D%7D%7D%7D'
          2        SEND_VAL                                                 1
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !0, $2
   24     5        INIT_FCALL                                               'convert_array'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $4      
          8        ASSIGN                                                   !1, $4
   25     9        INIT_FCALL                                               'print_r'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

Function convert_array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 30
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 30
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 25
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/6LTk1
function name:  convert_array
number of ops:  33
compiled vars:  !0 = $array, !1 = $retval, !2 = $row, !3 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    7     1        ASSIGN                                                   !1, <array>
    9     2      > FE_RESET_R                                       $5      !0, ->30
          3    > > FE_FETCH_R                                               $5, !2, ->30
   11     4    >   ASSIGN                                                   !3, <array>
   12     5        FETCH_DIM_R                                      ~8      !2, 'id'
          6        ASSIGN_DIM                                               !3, 'id'
          7        OP_DATA                                                  ~8
   13     8        FETCH_DIM_R                                      ~10     !2, 'source_name'
          9        ASSIGN_DIM                                               !3, 'text'
         10        OP_DATA                                                  ~10
   14    11        FETCH_DIM_R                                      ~12     !2, 'parent_id'
         12        ASSIGN_DIM                                               !3, 'parent_id'
         13        OP_DATA                                                  ~12
   15    14        FETCH_DIM_R                                      ~13     !2, 'children'
         15        COUNT                                            ~14     ~13
         16      > JMPZ                                                     ~14, ->25
   16    17    >   INIT_FCALL_BY_NAME                                       'convert_array'
         18        CHECK_FUNC_ARG                                           
         19        FETCH_DIM_FUNC_ARG                               $16     !2, 'children'
         20        SEND_FUNC_ARG                                            $16
         21        DO_FCALL                                      0  $17     
         22        ASSIGN_DIM                                               !3, 'nodes'
         23        OP_DATA                                                  $17
   15    24      > JMP                                                      ->27
   18    25    >   ASSIGN_DIM                                               !3, 'nodes'
         26        OP_DATA                                                  <array>
   19    27    >   ASSIGN_DIM                                               !1
         28        OP_DATA                                                  !3
    9    29      > JMP                                                      ->3
         30    >   FE_FREE                                                  $5
   21    31      > RETURN                                                   !1
   22    32*     > RETURN                                                   null

End of function convert_array

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.32 ms | 1019 KiB | 16 Q