Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\Coroutine\map(array $list, callable $fn, float $timeout = -1): array
The array list will be operated on with $fn
for each element.
The callback function to be executed for each element in the array.
The total timeout to wait for all callbacks to finish, it will return immediately after timeout. But the running coroutine will continue to execute to completion without stopping.
Must have at least OpenSwoole
v4.5.5
Similar to array_map, a callback function is applied to each element of the array.
<?php
OpenSwoole\Coroutine\map(array $list, callable $fn, float $timeout = -1): array
<?php
use function OpenSwoole\Coroutine\map;
function fatorial(int $n): int
{
return array_product(range($n, 1));
}
co::run(function () {
$results = map([2, 3, 4], 'fatorial');
print_r($results);
});