public static function getArrayItemByPointSeparatedKey(array& $data, string $key)
    {
        if (strpos($key, '.') !== false) {
            preg_match('/([a-zA-Z0-9_\-]+)\.([a-zA-Z0-9_\-\.]+)/', $key, $keys);
            if (!isset($data[$keys[1]])) {
                throw new Exception('Undefined index: '.$keys[1]);
            }
            if (!is_array($data[$keys[1]])) {
                throw new Exception("The element indexed {$keys[1]} isn't an array.");
            }
            return self::getArrayItemByPointSeparatedKey(
                $data[$keys[1]],
                $keys[2]
            );
        } elseif (isset($data[$key])) {
            return $data[$key];
        } else {
            throw new Exception('Undefined index: '.$key);
        }
    }
public static function getArrayItemByPointSeparatedKey(array& $data, string $key)
    {
        if (strpos($key, '.') !== false) {
            preg_match('/([a-zA-Z0-9_\-]+)\.([a-zA-Z0-9_\-\.]+)/', $key, $keys);
            if (!isset($data[$keys[1]])) {
                throw new Exception('Undefined index: '.$keys[1]);
            }
            if (!is_array($data[$keys[1]])) {
                throw new Exception("The element indexed {$keys[1]} isn't an array.");
            }
            return self::getArrayItemByPointSeparatedKey(
                $data[$keys[1]],
                $keys[2]
            );
        } elseif (isset($data[$key])) {
            return $data[$key];
        } else {
            throw new Exception('Undefined index: '.$key);
        }
    }
public static function getArrayItemByPointSeparatedKey ( array & $ data , string $ key ) { if ( strpos ( $ key , '.' ) !== false ) { preg_match ( '/([a-zA-Z0-9_\-]+)\.([a-zA-Z0-9_\-\.]+)/' , $ key , $ keys ) ; if ( ! isset ( $ data [ $ keys [ 1 ] ] ) ) { throw new Exception ( 'Undefined index: ' . $ keys [ 1 ] ) ; } if ( ! is_array ( $ data [ $ keys [ 1 ] ] ) ) { throw new Exception ( "The element indexed {$keys[1]} isn't an array." ) ; } return self :: getArrayItemByPointSeparatedKey ( $ data [ $ keys [ 1 ] ] , $ keys [ 2 ] ) ; } elseif ( isset ( $ data [ $ key ] ) ) { return $ data [ $ key ] ; } else { throw new Exception ( 'Undefined index: ' . $ key ) ; } }
The method returns a tree element by a key, which is formed as a string
separated by points and reflecting the nesting hierarchy.
@param mixed[] $data Input tree.
@param string $key The field name. The name of the nested field is formed by
the path of the tree the tiers of which are separated by the point.
@return mixed
@throws \extensions\validator\Exception
The method returns a tree element by a key which is formed as a string separated by points and reflecting the nesting hierarchy .