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;
}