Nathanmac\Utilities\Parser\Parser::getValueAtKey PHP Метод

getValueAtKey() приватный Метод

Return a value from the array identified from the key.
private getValueAtKey ( $key, $data ) : mixed
$key
$data
Результат mixed
    private function getValueAtKey($key, $data)
    {
        $keys = explode('.', $key);
        while (count($keys) > 1) {
            $key = array_shift($keys);
            // Wildcard Key
            if (preg_match($this->wildcards, $key) && is_array($data) && !empty($data)) {
                // Shift the first item of the array
                if (preg_match('/^:(index|item)\\[\\d+\\]$/', $key)) {
                    for ($x = substr($key, 7, -1); $x >= 0; $x--) {
                        if (empty($data)) {
                            return false;
                        }
                        $item = array_shift($data);
                    }
                } elseif ($key == ':last') {
                    $item = array_pop($data);
                } else {
                    $item = array_shift($data);
                }
                $data =& $item;
            } else {
                if (!isset($data[$key]) || !is_array($data[$key])) {
                    return false;
                }
                $data =& $data[$key];
            }
        }
        // Return value
        $key = array_shift($keys);
        if (preg_match($this->wildcards, $key)) {
            if (preg_match('/^:(index|item)\\[\\d+\\]$/', $key)) {
                for ($x = substr($key, 7, -1); $x >= 0; $x--) {
                    if (empty($data)) {
                        return false;
                    }
                    $item = array_shift($data);
                }
                return $item;
            } elseif ($key == ':last') {
                return array_pop($data);
            }
            return array_shift($data);
            // First Found
        }
        return $data[$key];
    }