3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'key1' => [ 'key2' => [ 'key3' => 'YAY I GOT IT' ] ] ]; $keys = ['key1', 'key2', 'key3']; function findValueForKeys($data, $keys) { $key = array_shift($keys); if (is_array($data)) { if (array_key_exists($key, $data)) { return findValueForKeys($data[$key], $keys); } } return $data; }; echo "Searching... got the value: " . findValueForKeys($array, $keys);

preferences:
30.3 ms | 404 KiB | 5 Q