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['category_id']]['name'] = $row['name']; $categoryArray[$row['parent_id']][$row['category_id']]['elements'] = $categoryArray[$row['category_id']]; unset($categoryArray[$row['category_id']]); } else { $categoryArray[$row['parent_id']][$row['category_id']]['name'] = $row['name']; } } echo "first stage \n"; print_r($categoryArray); // second stage echo "\n\n"; getCategory($categoryArray); function getCategory($array){ foreach($array as $row){ if(is_array($row)) { echo('<li>'.$row.'<ul>'); getCategory($row); echo('</ul></li>'); } else { echo('<li>'.$row.'</li>'); } } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 35
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 35
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 27
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/o3Ys4
function name:  (null)
number of ops:  45
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, ->35
          7    > > FE_FETCH_R                                               $8, !2, ->35
   22     8    >   FETCH_DIM_R                                      ~9      !2, 'category_id'
          9        ISSET_ISEMPTY_DIM_OBJ                         0          !1, ~9
         10      > JMPZ                                                     ~10, ->27
   23    11    >   FETCH_DIM_R                                      ~11     !2, 'category_id'
         12        FETCH_DIM_R                                      ~14     !2, 'name'
         13        FETCH_DIM_W                                      $12     !1, ~11
         14        ASSIGN_DIM                                               $12, 'name'
         15        OP_DATA                                                  ~14
   24    16        FETCH_DIM_R                                      ~15     !2, 'parent_id'
         17        FETCH_DIM_R                                      ~17     !2, 'category_id'
         18        FETCH_DIM_R                                      ~20     !2, 'category_id'
         19        FETCH_DIM_R                                      ~21     !1, ~20
         20        FETCH_DIM_W                                      $16     !1, ~15
         21        FETCH_DIM_W                                      $18     $16, ~17
         22        ASSIGN_DIM                                               $18, 'elements'
         23        OP_DATA                                                  ~21
   25    24        FETCH_DIM_R                                      ~22     !2, 'category_id'
         25        UNSET_DIM                                                !1, ~22
         26      > JMP                                                      ->34
   27    27    >   FETCH_DIM_R                                      ~23     !2, 'parent_id'
         28        FETCH_DIM_R                                      ~25     !2, 'category_id'
         29        FETCH_DIM_R                                      ~28     !2, 'name'
         30        FETCH_DIM_W                                      $24     !1, ~23
         31        FETCH_DIM_W                                      $26     $24, ~25
         32        ASSIGN_DIM                                               $26, 'name'
         33        OP_DATA                                                  ~28
   21    34    > > JMP                                                      ->7
         35    >   FE_FREE                                                  $8
   31    36        ECHO                                                     'first+stage+%0A'
   32    37        INIT_FCALL                                               'print_r'
         38        SEND_VAR                                                 !1
         39        DO_ICALL                                                 
   36    40        ECHO                                                     '%0A%0A'
   37    41        INIT_FCALL_BY_NAME                                       'getCategory'
         42        SEND_VAR_EX                                              !1
         43        DO_FCALL                                      0          
   49    44      > RETURN                                                   1

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

End of function getcategory

Class A1:
Function rows:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/o3Ys4
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:
213.23 ms | 1404 KiB | 15 Q