array_filter

Supported Versions: PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8
Filters elements of an array using a callback function
<?php array_filter(array $array, ?callable $callback = null, int $mode = 0): array
<?php         if ($docComment = $reflection->getDocComment()) {

            $namesToCheck = [

                ...$namesToCheck,

                ...array_values(array_filter(

                    explode(PHP_EOL, $docComment),

                    fn (string $line): bool => ! str_contains($line, '* @',

                    ))),

            ];

        }
<?php     private function getMethodNames(ReflectionClass $reflection): array

    {

        $methods = array_filter(

            $reflection->getMethods(),

            function (ReflectionMethod $method) use ($reflection): bool {

                foreach ($reflection->getTraits() as $trait) {

                    if ($trait->hasMethod($method->getName())) {

                        return false;

                    }

                }



                return $method->class === $reflection->name;

            },

        );



        foreach ($methods as $method) {

            $namesToCheck[] = $method->getName();
<?php             if ($docComment = $method->getDocComment()) {

                $namesToCheck = [

                    ...$namesToCheck,

                    ...array_values(array_filter(

                        explode(PHP_EOL, $docComment),

                        fn (string $line): bool => ! str_contains($line, '* @',

                        ))),

                ];

            }

        }
<?php     private function getPropertyNames(ReflectionClass $reflection): array

    {

        $properties = array_filter(

            $reflection->getProperties(),

            function (ReflectionProperty $property) use ($reflection): bool {

                foreach ($reflection->getTraits() as $trait) {

                    if ($trait->hasProperty($property->getName())) {

                        return false;

                    }

                }



                return $property->class === $reflection->name;

            },

        );



        $propertiesNames = array_map(

            fn (ReflectionProperty $property): string => $property->getName(),
<?php         $contentsArray = explode(PHP_EOL, $file->getContents());

        $contentsArrayLines = array_map(fn ($lineNumber): int => $lineNumber + 1, array_keys($contentsArray));



        $lines = array_values(array_filter(

            array_map(

                fn (string $line, int $lineNumber): ?int => str_contains($line, $misspellingWord) ? $lineNumber : null,

                $contentsArray,

                $contentsArrayLines,

            ),

        ));



        if ($lines === []) {

            return 0;
<?php         $misspellings = $this->cache->has($text) ? $this->cache->get($text) : $this->getMisspellings($text);



        return array_filter($misspellings,

            fn (Misspelling $misspelling): bool => ! $this->config->isWordIgnored($misspelling->word),

        );

    }
<?php     private function takeSuggestions(array $suggestions): array

    {

        $suggestions = array_filter($suggestions,

            fn (string $suggestion): bool => in_array(preg_match('/[^a-zA-Z]/', $suggestion), [0, false], true)

        );



        return array_slice(array_values(array_unique($suggestions)), 0, 4);

    }
<?php             $suggestions = explode(', ', trim($suggestionsAsString));



            return new Misspelling($word, $this->takeSuggestions($suggestions));

        }, array_filter(explode(PHP_EOL, $output), fn (string $line): bool => str_starts_with($line, '&'))));

    }
<?php     {

        $path = sprintf('%s/%s.stub', self::PRESET_STUBS_DIRECTORY, $preset);



        return array_values(array_filter(array_map('trim', explode("\n", (string) file_get_contents($path)))));

    }