3v4l.org

run code in 300+ PHP versions simultaneously
<?php function hasNonEmptyArray(array $array): bool { try { array_walk_recursive( $array, fn($v, $k) => throw new Exception("Found element $k\n") ); return false; } catch (Exception $e) { echo $e->getMessage(); return true; } } $array = [ [ 'one' => [], 'two' => [ 'a' => [ 'foo' => [], ], 'b' => [] ], 'three' => [ 'c' => [ 'fizz' => 'buzz' ] ] ] ]; var_export(hasNonEmptyArray($array));
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Found element fizz true

preferences:
52.44 ms | 406 KiB | 5 Q