PHP 8.5.0 Alpha 4 available for testing

Voting

: seven minus two?
(Example: nine)

The Note You're Voting On

wallfur at gmail dot com
1 year ago
If you need access to the keys of the array in your callback, this alternative uses the same signatures as array_reduce() and its callback, with the addition of a $key argument:
<?php
function array_reduce_assoc(array $array, callable $callback, mixed $initial = null): mixed
{
foreach (
$array as $key => $item)
{
$initial = call_user_func($callback, $initial, $item, $key);
}
return
$initial;
}

<< Back to user notes page

To Top