3v4l.org

run code in 300+ PHP versions simultaneously
<?php // I have a table `categoreis` to store products' categories information // it use categories_id and parent_id to identify the level relationship between those categories // now I want a function(tep_get_leaf_categories() below) to get all leaf categories for a passed in category_id // say tep_get_leaf_categories(360) will get all leaf categories id as an array of category 360 // this function get all subcategories, or child-categories for $category_id function tep_get_subcategories($category_id) { $subcategories_raw = tep_db_query('SELECT ca.categories_id FROM categories ca LEFT JOIN categoreis cb ON ca.parent_id = cb.categories_id WHERE cb.categoreis_id = ' . (int) $category_id); $subcategories = array(); if (mysql_num_rows($subcategories_raw) >= 1) { while ($row = mysql_fetch_assoc($subcategories_raw)) { $category_id = $row['categories_id']; $subcategories[] = $category_id; } } return $subcategories; } // this is the function that I'm working on, to get the leaf category of $category_id function tep_get_leaf_categories($category_id) { $sub_categories = tep_get_subcategories($category_id); // no sub categories found:return self as result if (count($sub_categories) === 0) { $result[] = $category_id; } else { foreach ($sub_categories as $category_id) { tep_get_leaf_categories($category_id, $result); } } return $result; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SkHD8
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E > > RETURN                                                   1

Function tep_get_subcategories:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 23
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 14
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 14
Branch analysis from position: 23
Branch analysis from position: 14
Branch analysis from position: 23
filename:       /in/SkHD8
function name:  tep_get_subcategories
number of ops:  25
compiled vars:  !0 = $category_id, !1 = $subcategories_raw, !2 = $subcategories, !3 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
    9     1        INIT_FCALL_BY_NAME                                       'tep_db_query'
   13     2        CAST                                          4  ~4      !0
          3        CONCAT                                           ~5      'SELECT+ca.categories_id%0A%09%09%09%09%09%09%09FROM+categories+ca%0A%09%09%09%09%09%09%09LEFT+JOIN+categoreis+cb%0A%09%09%09%09%09%09%09%09ON+ca.parent_id+%3D+cb.categories_id%0A%09%09%09%09%09%09%09WHERE+cb.categoreis_id+%3D+', ~4
          4        SEND_VAL_EX                                              ~5
          5        DO_FCALL                                      0  $6      
    9     6        ASSIGN                                                   !1, $6
   15     7        ASSIGN                                                   !2, <array>
   16     8        INIT_FCALL_BY_NAME                                       'mysql_num_rows'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0  $9      
         11        IS_SMALLER_OR_EQUAL                                      1, $9
         12      > JMPZ                                                     ~10, ->23
   17    13    > > JMP                                                      ->18
   18    14    >   FETCH_DIM_R                                      ~11     !3, 'categories_id'
         15        ASSIGN                                                   !0, ~11
   19    16        ASSIGN_DIM                                               !2
         17        OP_DATA                                                  !0
   17    18    >   INIT_FCALL_BY_NAME                                       'mysql_fetch_assoc'
         19        SEND_VAR_EX                                              !1
         20        DO_FCALL                                      0  $14     
         21        ASSIGN                                           ~15     !3, $14
         22      > JMPNZ                                                    ~15, ->14
   23    23    > > RETURN                                                   !2
   24    24*     > RETURN                                                   null

End of function tep_get_subcategories

Function tep_get_leaf_categories:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 18
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/SkHD8
function name:  tep_get_leaf_categories
number of ops:  21
compiled vars:  !0 = $category_id, !1 = $sub_categories, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   28     1        INIT_FCALL                                               'tep_get_subcategories'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   31     5        COUNT                                            ~5      !1
          6        IS_IDENTICAL                                             ~5, 0
          7      > JMPZ                                                     ~6, ->11
   32     8    >   ASSIGN_DIM                                               !2
          9        OP_DATA                                                  !0
         10      > JMP                                                      ->19
   34    11    > > FE_RESET_R                                       $8      !1, ->18
         12    > > FE_FETCH_R                                               $8, !0, ->18
   35    13    >   INIT_FCALL_BY_NAME                                       'tep_get_leaf_categories'
         14        SEND_VAR_EX                                              !0
         15        SEND_VAR_EX                                              !2
         16        DO_FCALL                                      0          
   34    17      > JMP                                                      ->12
         18    >   FE_FREE                                                  $8
   39    19    > > RETURN                                                   !2
   40    20*     > RETURN                                                   null

End of function tep_get_leaf_categories

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.57 ms | 1403 KiB | 14 Q