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) );

preferences:
107.46 ms | 407 KiB | 5 Q