3v4l.org

run code in 300+ PHP versions simultaneously
<?php $finalresult = array ( 101 => array( "username"=> "1st user", "children"=> array ( 104=> array ( "username"=> "4th user", "children"=> array() ), 105=> array ( "username"=> "5th user", "children"=> array() ), 108=> array ( "username"=> "new guy", "children"=> array() ) ) ), 102=> array ( "username"=> "2nd user", "children"=> array() ), 103=> array ( "username"=> "3rd user", "children"=> array() ) ); function count_children($tree) { $count = 0; foreach ($tree as $child) { $count++; if (is_array($child['children'])) { $count += count_children($child['children']); } } return $count; } echo count_children($finalresult);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5rSiv
function name:  (null)
number of ops:  6
compiled vars:  !0 = $finalresult
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   42     1        INIT_FCALL                                               'count_children'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
          5      > RETURN                                                   1

Function count_children:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 15
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 14
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/5rSiv
function name:  count_children
number of ops:  18
compiled vars:  !0 = $tree, !1 = $count, !2 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   32     1        ASSIGN                                                   !1, 0
   33     2      > FE_RESET_R                                       $4      !0, ->15
          3    > > FE_FETCH_R                                               $4, !2, ->15
   34     4    >   PRE_INC                                                  !1
   35     5        FETCH_DIM_R                                      ~6      !2, 'children'
          6        TYPE_CHECK                                  128          ~6
          7      > JMPZ                                                     ~7, ->14
   36     8    >   INIT_FCALL_BY_NAME                                       'count_children'
          9        CHECK_FUNC_ARG                                           
         10        FETCH_DIM_FUNC_ARG                               $8      !2, 'children'
         11        SEND_FUNC_ARG                                            $8
         12        DO_FCALL                                      0  $9      
         13        ASSIGN_OP                                     1          !1, $9
   33    14    > > JMP                                                      ->3
         15    >   FE_FREE                                                  $4
   39    16      > RETURN                                                   !1
   40    17*     > RETURN                                                   null

End of function count_children

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.38 ms | 1002 KiB | 14 Q