Let's see an example of array_reduce() to get the frequency of letters.
<?php
$items = "Hello";
$frequencies = array_reduce(str_split($items),
function($result, $item) {
if (isset($result[$item])) {
$result[$item] += 1;
} else {
$result[$item] = 1;
}
return $result;
},
[] // note the initial is an array
);
print_r($frequencies);
?>
and output should be like:
Array
(
[H] => 1
[e] => 1
[l] => 2
[o] => 1
)