3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CategoryTree { private $catTree = array(); public function addCategory($category, $parent) { if($parent == null){ echo count(array_column($this->catTree, 'parent'), $parent); } else{ } $temp = array("category" => $category,"parent" => $parent); array_push($this->catTree,$temp); } public function getChildren($parent) { $that = $this; $keys = array_keys(array_column($this->catTree, 'parent'), $parent); return array_map(function($k) use ($that){return $that->catTree[$k]['category'];}, $keys); } } // For testing purposes (do not submit uncommented): $c = new CategoryTree; $c->addCategory('A', null); $c->addCategory('B', 'A'); $c->addCategory('C', 'A'); echo implode(',', $c->getChildren('A'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HcKit
function name:  (null)
number of ops:  24
compiled vars:  !0 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   NEW                                              $1      'CategoryTree'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   29     3        INIT_METHOD_CALL                                         !0, 'addCategory'
          4        SEND_VAL_EX                                              'A'
          5        SEND_VAL_EX                                              null
          6        DO_FCALL                                      0          
   30     7        INIT_METHOD_CALL                                         !0, 'addCategory'
          8        SEND_VAL_EX                                              'B'
          9        SEND_VAL_EX                                              'A'
         10        DO_FCALL                                      0          
   32    11        INIT_METHOD_CALL                                         !0, 'addCategory'
         12        SEND_VAL_EX                                              'C'
         13        SEND_VAL_EX                                              'A'
         14        DO_FCALL                                      0          
   34    15        INIT_FCALL                                               'implode'
         16        SEND_VAL                                                 '%2C'
         17        INIT_METHOD_CALL                                         !0, 'getChildren'
         18        SEND_VAL_EX                                              'A'
         19        DO_FCALL                                      0  $7      
         20        SEND_VAR                                                 $7
         21        DO_ICALL                                         $8      
         22        ECHO                                                     $8
         23      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FHcKit%3A22%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HcKit
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $k, !1 = $that
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        FETCH_OBJ_R                                      ~2      !1, 'catTree'
          3        FETCH_DIM_R                                      ~3      ~2, !0
          4        FETCH_DIM_R                                      ~4      ~3, 'category'
          5      > RETURN                                                   ~4
          6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHcKit%3A22%240

Class CategoryTree:
Function addcategory:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/HcKit
function name:  addCategory
number of ops:  24
compiled vars:  !0 = $category, !1 = $parent, !2 = $temp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        IS_EQUAL                                                 !1, null
          3      > JMPZ                                                     ~3, ->15
    9     4    >   INIT_FCALL                                               'count'
          5        INIT_FCALL                                               'array_column'
          6        FETCH_OBJ_R                                      ~4      'catTree'
          7        SEND_VAL                                                 ~4
          8        SEND_VAL                                                 'parent'
          9        DO_ICALL                                         $5      
         10        SEND_VAR                                                 $5
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $6      
         13        ECHO                                                     $6
         14      > JMP                                                      ->15
   14    15    >   INIT_ARRAY                                       ~7      !0, 'category'
         16        ADD_ARRAY_ELEMENT                                ~7      !1, 'parent'
         17        ASSIGN                                                   !2, ~7
   15    18        INIT_FCALL                                               'array_push'
         19        FETCH_OBJ_W                                      $9      'catTree'
         20        SEND_REF                                                 $9
         21        SEND_VAR                                                 !2
         22        DO_ICALL                                                 
   16    23      > RETURN                                                   null

End of function addcategory

Function getchildren:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HcKit
function name:  getChildren
number of ops:  21
compiled vars:  !0 = $parent, !1 = $that, !2 = $keys
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   20     1        FETCH_THIS                                       ~3      
          2        ASSIGN                                                   !1, ~3
   21     3        INIT_FCALL                                               'array_keys'
          4        INIT_FCALL                                               'array_column'
          5        FETCH_OBJ_R                                      ~5      'catTree'
          6        SEND_VAL                                                 ~5
          7        SEND_VAL                                                 'parent'
          8        DO_ICALL                                         $6      
          9        SEND_VAR                                                 $6
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $7      
         12        ASSIGN                                                   !2, $7
   22    13        INIT_FCALL                                               'array_map'
         14        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHcKit%3A22%240'
         15        BIND_LEXICAL                                             ~9, !1
         16        SEND_VAL                                                 ~9
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                         $10     
         19      > RETURN                                                   $10
   23    20*     > RETURN                                                   null

End of function getchildren

End of class CategoryTree.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.21 ms | 1404 KiB | 25 Q