3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getFromKeyPath(array $array, array $keys) { foreach ($keys as $index => $key) { if (!key_exists($key, $array)) { throw new Exception("key $key not found at level index $index"); } $array = $array[$key]; } return $array; } $array = ['a' => ['b' => ['c' => 'value'], 'd' => 3]]; $keys = ['a', 'b', 'c']; try { var_export(getFromKeyPath($array, $keys)); } catch (Exception $e) { echo $e->getMessage(); }

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
162 ms | 1958 KiB | 11 Q