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 public function then(Closure $destination)
{
$pipeline = array_reduce(
array_reverse($this->pipes()), $this->carry(), $this->prepareDestination($destination)
);
return $pipeline($this->passable);
}
<?php public function parseNamedParameters($parameters)
{
return array_reduce($parameters, function ($result, $item) {
[$key, $value] = array_pad(explode('=', $item, 2), 2, null);
$result[$key] = $value;
return $result;
});
}
<?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,
);
}
}
<?php private function compose(callable ...$functions): ?callable
{
return array_reduce($functions, static function (?callable $carry, callable $item): callable {
if ($carry === null) {
return $item;
}
return /**
static function ($value) use ($carry, $item) {
return $item($carry($value));
};
});
}
}
<?php $cancellationQueue->enqueue($initialValue);
\array_reduce($promisesOrValues, $wrappedReduceFunc, resolve($initialValue))
->done($resolve, $reject);
}, $cancellationQueue);
}
<?php public function reduce(callable $f, $initial = null)
{
return array_reduce($this->items, $f, $initial);
}
public function filter(?callable $f = null): self
<?php protected function buildProperties(array $data)
{
return trim(
array_reduce(
$data,
function ($output, $property) {
$output .= ' public $' . $property . ';' . PHP_EOL . PHP_EOL;
return $output;
},
''
)
);
}
<?php protected function buildAssignments(array $data)
{
return trim(
array_reduce(
$data,
function ($output, $property) {
$output .= ' $this->' . $property . ' = $' . $property . ';' . PHP_EOL;
return $output;
},
''
)
);
}