Google\Cloud\NaturalLanguage\Annotation::filter PHP Method

filter() private method

Filters an array of items based on the provided type.
private filter ( array $items, array $path, string $type ) : array | null
$items array The items to iterate.
$path array The path to the value to compare against the provided type.
$type string The type to filter on.
return array | null
    private function filter($items, $path, $type)
    {
        if (!$items) {
            return null;
        }
        return array_filter($items, function ($item) use($path, $type) {
            $itemCopy = $item;
            // key into the value with the given path
            foreach ($path as $key) {
                $itemCopy = $itemCopy[$key];
            }
            if (strtolower($itemCopy) === strtolower($type)) {
                return $item;
            }
        });
    }