<?php $array = [ 'key1' => [ 'key2' => [ 'key3' => 'YAY I GOT IT' ] ] ]; $keys = ['key1', 'key2', 'key3']; function findValueForKeys($data, $keys) { $key = array_shift($keys); echo "Searching for: '$key' in: '" . print_r($data, true) . "'" . PHP_EOL; if (!is_array($data)) { return $data; } if (array_key_exists($key, $data)) { if (!is_array($data[$key])) { echo 'Got the last value. It is: ' . $data[$key] . PHP_EOL; return $data[$key]; } findValueForKeys($data[$key], $keys); } else { return $data; } }; echo "Searching... got the value: " . findValueForKeys($array, $keys);
You have javascript disabled. You will not be able to edit any code.