3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A1 { public function rows() { $a = array(); $a[] = array('parent_id' => 10, 'category_id' => 13, 'name' => 'id13'); $a[] = array('parent_id' => 8, 'category_id' => 12, 'name' => 'id12'); $a[] = array('parent_id' => 7, 'category_id' => 11, 'name' => 'id11'); $a[] = array('parent_id' => 7, 'category_id' => 10, 'name' => 'id10'); $a[] = array('parent_id' => 0, 'category_id' => 9, 'name' => 'id9'); $a[] = array('parent_id' => 0, 'category_id' => 8, 'name' => 'id8'); $a[] = array('parent_id' => 0, 'category_id' => 7, 'name' => 'id7'); return $a; } } $query = new A1; $categoryArray = array(); foreach($query->rows() as $row) { if(isset($categoryArray[$row['category_id']])) { $categoryArray[$row['parent_id']][$row['category_id']] = $categoryArray[$row['category_id']]; unset($categoryArray[$row['category_id']]); } else { $categoryArray[$row['parent_id']][$row['category_id']] = $row['name']; } } echo 'first stage <br>'; print_r($categoryArray); // second stage getLine($categoryArray()); function getLine($array){ foreach($array as $row){ if(is_array($row)) { echo('<ul>'); getLine($row); echo('</ul>'); } else { echo('<li>'.$row.'</li>'); } } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 28
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 28
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 21
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/W6E9e
function name:  (null)
number of ops:  39
compiled vars:  !0 = $query, !1 = $categoryArray, !2 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   NEW                                              $3      'A1'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
   19     3        ASSIGN                                                   !1, <array>
   21     4        INIT_METHOD_CALL                                         !0, 'rows'
          5        DO_FCALL                                      0  $7      
          6      > FE_RESET_R                                       $8      $7, ->28
          7    > > FE_FETCH_R                                               $8, !2, ->28
   22     8    >   FETCH_DIM_R                                      ~9      !2, 'category_id'
          9        ISSET_ISEMPTY_DIM_OBJ                         0          !1, ~9
         10      > JMPZ                                                     ~10, ->21
   23    11    >   FETCH_DIM_R                                      ~11     !2, 'parent_id'
         12        FETCH_DIM_R                                      ~13     !2, 'category_id'
         13        FETCH_DIM_R                                      ~15     !2, 'category_id'
         14        FETCH_DIM_R                                      ~16     !1, ~15
         15        FETCH_DIM_W                                      $12     !1, ~11
         16        ASSIGN_DIM                                               $12, ~13
         17        OP_DATA                                                  ~16
   24    18        FETCH_DIM_R                                      ~17     !2, 'category_id'
         19        UNSET_DIM                                                !1, ~17
         20      > JMP                                                      ->27
   26    21    >   FETCH_DIM_R                                      ~18     !2, 'parent_id'
         22        FETCH_DIM_R                                      ~20     !2, 'category_id'
         23        FETCH_DIM_R                                      ~22     !2, 'name'
         24        FETCH_DIM_W                                      $19     !1, ~18
         25        ASSIGN_DIM                                               $19, ~20
         26        OP_DATA                                                  ~22
   21    27    > > JMP                                                      ->7
         28    >   FE_FREE                                                  $8
   30    29        ECHO                                                     'first+stage+%3Cbr%3E'
   31    30        INIT_FCALL                                               'print_r'
         31        SEND_VAR                                                 !1
         32        DO_ICALL                                                 
   36    33        INIT_FCALL_BY_NAME                                       'getLine'
         34        INIT_DYNAMIC_CALL                                        !1
         35        DO_FCALL                                      0  $24     
         36        SEND_VAR_NO_REF_EX                                       $24
         37        DO_FCALL                                      0          
   48    38      > RETURN                                                   1

Function getline:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 15
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 15
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/W6E9e
function name:  getLine
number of ops:  17
compiled vars:  !0 = $array, !1 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   39     1      > FE_RESET_R                                       $2      !0, ->15
          2    > > FE_FETCH_R                                               $2, !1, ->15
   40     3    >   TYPE_CHECK                                  128          !1
          4      > JMPZ                                                     ~3, ->11
   41     5    >   ECHO                                                     '%3Cul%3E'
   42     6        INIT_FCALL_BY_NAME                                       'getLine'
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0          
   43     9        ECHO                                                     '%3C%2Ful%3E'
         10      > JMP                                                      ->14
   45    11    >   CONCAT                                           ~5      '%3Cli%3E', !1
         12        CONCAT                                           ~6      ~5, '%3C%2Fli%3E'
         13        ECHO                                                     ~6
   39    14    > > JMP                                                      ->2
         15    >   FE_FREE                                                  $2
   48    16      > RETURN                                                   null

End of function getline

Class A1:
Function rows:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/W6E9e
function name:  rows
number of ops:  17
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                   !0, <array>
    6     1        ASSIGN_DIM                                               !0
          2        OP_DATA                                                  <array>
    7     3        ASSIGN_DIM                                               !0
          4        OP_DATA                                                  <array>
    8     5        ASSIGN_DIM                                               !0
          6        OP_DATA                                                  <array>
    9     7        ASSIGN_DIM                                               !0
          8        OP_DATA                                                  <array>
   10     9        ASSIGN_DIM                                               !0
         10        OP_DATA                                                  <array>
   11    11        ASSIGN_DIM                                               !0
         12        OP_DATA                                                  <array>
   12    13        ASSIGN_DIM                                               !0
         14        OP_DATA                                                  <array>
   14    15      > RETURN                                                   !0
   15    16*     > RETURN                                                   null

End of function rows

End of class A1.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.72 ms | 1404 KiB | 15 Q