3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [1,2,3 => [4, 5, 6, 7=>[8]]], [1,2,3 => [4, 5, 6, 7=>[8, 9]]] ]; function recursive_count($array, $max_depth=12) { static $stack_depth = 0; $total = 0; foreach($array as $val) { if (is_array($val)) { $stack_depth++; if($max_depth < $stack_depth) { $stack_depth = 0; throw new Exception("Stack level too deep! Stack Limit: $max_depth"); } $total += recursive_count($val, $max_depth); } else { $total++; } } $stack_depth--; return $total; } var_dump(recursive_count($array,2));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EDIhJ
function name:  (null)
number of ops:  9
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   28     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'recursive_count'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 2
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function recursive_count:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 26
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 26
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 24
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 18
Branch analysis from position: 11
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/EDIhJ
function name:  recursive_count
number of ops:  30
compiled vars:  !0 = $array, !1 = $max_depth, !2 = $stack_depth, !3 = $total, !4 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      12
   10     2        BIND_STATIC                                              !2
   11     3        ASSIGN                                                   !3, 0
   12     4      > FE_RESET_R                                       $6      !0, ->26
          5    > > FE_FETCH_R                                               $6, !4, ->26
   13     6    >   TYPE_CHECK                                  128          !4
          7      > JMPZ                                                     ~7, ->24
   14     8    >   PRE_INC                                                  !2
   15     9        IS_SMALLER                                               !1, !2
         10      > JMPZ                                                     ~9, ->18
   16    11    >   ASSIGN                                                   !2, 0
   17    12        NEW                                              $11     'Exception'
         13        NOP                                                      
         14        FAST_CONCAT                                      ~12     'Stack+level+too+deep%21++Stack+Limit%3A+', !1
         15        SEND_VAL_EX                                              ~12
         16        DO_FCALL                                      0          
         17      > THROW                                         0          $11
   19    18    >   INIT_FCALL_BY_NAME                                       'recursive_count'
         19        SEND_VAR_EX                                              !4
         20        SEND_VAR_EX                                              !1
         21        DO_FCALL                                      0  $14     
         22        ASSIGN_OP                                     1          !3, $14
         23      > JMP                                                      ->25
   22    24    >   PRE_INC                                                  !3
   12    25    > > JMP                                                      ->5
         26    >   FE_FREE                                                  $6
   25    27        PRE_DEC                                                  !2
   26    28      > RETURN                                                   !3
   27    29*     > RETURN                                                   null

End of function recursive_count

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.21 ms | 1403 KiB | 16 Q