extract_key($data, $key_array); } /** * Recursively extract keys from the data array. Basically, $data.foo.bar is * represented by sending $data, ['foo', 'bar']. If you end a key with * [] it will get every instance of that value inside the current array. * * @param mixed $data The data to traverse. You can send anything here but * don't expect to not get an exception if you try to traverse things like * non-existent indices. * @param array $key_array The array keys to use to traverse $data. * * @throws \Exception If any of the provided keys do not exist in the data. * * @return mixed The requested data. */ private function extract_key($data, $key_array) { $key = array_shift($key_array); if($key === null) { return $data; } else { if(substr($key, -2) === '[]') { return array_column($data, substr($key, 0, strlen($key) - 2)); } else { if(array_key_exists($key, $data) === false) { throw new \Exception('Invalid path string.', 1500); } else { return $this->extract_key($data[$key], $key_array); } } } } }