array_reduce

Supported Versions: PHP 4 >= 4.0.5, PHP 5, PHP 7, PHP 8
Iteratively reduce the array to a single value using a callback function
<?php array_reduce(array $array, callable $callback, mixed $initial = null): mixed
<?php         $classAttributes = [];



        foreach ($classAvailableAttributes as $attribute) {

            $classAttributes = array_reduce(

                $methods,

                fn (array $carry, TestCaseMethodFactory $methodFactory): array => (new $attribute())->__invoke($methodFactory, $carry),

                $classAttributes

            );

        }



        $methodsCode = implode('', array_map(
<?php                 ]);

        }, $targets);



        $this->targets = array_reduce($targets, function (array $accumulator, string $target): array {

            if (($matches = glob($target)) !== false) {

                foreach ($matches as $file) {

                    $accumulator[] = (string) realpath($file);

                }

            }



            return $accumulator;

        }, []);

    }
<?php             fn (object|string $handler): bool => $handler instanceof HandlesArguments,

        );



        $filteredArguments = array_reduce(

            $handlers,

            fn (array $arguments, HandlesArguments $handler): array => $handler->handleArguments($arguments),

            $arguments

        );



        $exitCode = $this->paratestCommand()->run(new ArgvInput($filteredArguments), new CleanConsoleOutput());
<?php             fn (object|string $handler): bool => $handler instanceof HandlersWorkerArguments,

        );



        return array_reduce(

            $handlers,

            fn (array $arguments, HandlersWorkerArguments $handler): array => $handler->handleWorkerArguments($arguments),

            $arguments

        );

    }
<?php     public function handleArguments(array $arguments): array

    {

        $args = array_reduce(self::ARGS_TO_REMOVE, fn (array $args, string $arg): array => $this->popArgument($arg, $args), $arguments);



        return $this->pushArgument('--runner='.WrapperRunner::class, $args);

    }
<?php             return str_starts_with($currentTestFile, $datasetScope);

        }, ARRAY_FILTER_USE_KEY);



        $closestScopeDatasetKey = array_reduce(

            array_keys($matchingDatasets),

            fn (string|int|null $keyA, string|int|null $keyB): string|int|null => $keyA !== null && strlen((string) $keyA) > strlen((string) $keyB) ? $keyA : $keyB

        );



        if ($closestScopeDatasetKey === null) {

            throw new DatasetDoesNotExist($name);
<?php     public function run(): void

    {

        $pipeline = array_reduce(

            array_reverse($this->pipes),

            $this->carry(),

            function (): void {

                call_user_func_array($this->closure, $this->passables);

            }

        );



        $pipeline();

    }
<?php     public function count(string $name): int

    {

        return array_reduce(

            $this->messages,

            static fn (int $total, HigherOrderMessage $message): int => $total + (int) ($name === $message->name),

            0,

        );

    }

}