3v4l.org

run code in 300+ PHP versions simultaneously
<?php $testArray= [ 'test1' => 'SingleValue1', 'test2' => 'SingleValue2' ]; function deepestArrays(array $array, int $level = 0, array &$lowest = []): array { $subarrays = array_filter($array, 'is_array'); if ($subarrays) { // a deeper level exists foreach ($subarrays as $subarray) { deepestArrays($subarray, $level + 1, $lowest); // recurse each subarray } } else { // deepest level in branch $lowestLevel = key($lowest) ?? $level; // if lowest array is empty, key will be null, fallback to $level value if ($lowestLevel === $level) { $lowest[$level][] = $array; // push the array into the results } elseif ($lowestLevel < $level) { $lowest = [$level => [$array]]; // overwrite with new lowest array } } return current($lowest); // return the deepest array } var_export( deepestArrays($testArray) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NIFWr
function name:  (null)
number of ops:  8
compiled vars:  !0 = $testArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   25     1        INIT_FCALL                                               'var_export'
   26     2        INIT_FCALL                                               'deepestarrays'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
   25     6        DO_ICALL                                                 
   27     7      > RETURN                                                   1

Function deepestarrays:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 20
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 18
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 18
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 32
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 37
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
filename:       /in/NIFWr
function name:  deepestArrays
number of ops:  44
compiled vars:  !0 = $array, !1 = $level, !2 = $lowest, !3 = $subarrays, !4 = $subarray, !5 = $lowestLevel
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
          2        RECV_INIT                                        !2      <array>
    9     3        INIT_FCALL                                               'array_filter'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 'is_array'
          6        DO_ICALL                                         $6      
          7        ASSIGN                                                   !3, $6
   10     8      > JMPZ                                                     !3, ->20
   11     9    > > FE_RESET_R                                       $8      !3, ->18
         10    > > FE_FETCH_R                                               $8, !4, ->18
   12    11    >   INIT_FCALL_BY_NAME                                       'deepestArrays'
         12        SEND_VAR_EX                                              !4
         13        ADD                                              ~9      !1, 1
         14        SEND_VAL_EX                                              ~9
         15        SEND_VAR_EX                                              !2
         16        DO_FCALL                                      0          
   11    17      > JMP                                                      ->10
         18    >   FE_FREE                                                  $8
   10    19      > JMP                                                      ->37
   15    20    >   INIT_FCALL                                               'key'
         21        SEND_VAR                                                 !2
         22        DO_ICALL                                         $11     
         23        COALESCE                                         ~12     $11
         24        QM_ASSIGN                                        ~12     !1
         25        ASSIGN                                                   !5, ~12
   16    26        IS_IDENTICAL                                             !5, !1
         27      > JMPZ                                                     ~14, ->32
   17    28    >   FETCH_DIM_W                                      $15     !2, !1
         29        ASSIGN_DIM                                               $15
         30        OP_DATA                                                  !0
   16    31      > JMP                                                      ->37
   18    32    >   IS_SMALLER                                               !5, !1
         33      > JMPZ                                                     ~17, ->37
   19    34    >   INIT_ARRAY                                       ~18     !0
         35        INIT_ARRAY                                       ~19     ~18, !1
         36        ASSIGN                                                   !2, ~19
   22    37    >   INIT_FCALL                                               'current'
         38        SEND_VAR                                                 !2
         39        DO_ICALL                                         $21     
         40        VERIFY_RETURN_TYPE                                       $21
         41      > RETURN                                                   $21
   23    42*       VERIFY_RETURN_TYPE                                       
         43*     > RETURN                                                   null

End of function deepestarrays

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.23 ms | 1010 KiB | 18 Q