I wrote this to calculate harmonic averages in my shares program. Hopefully this can help someone who doesn't want to use PECL. The function accepts an unlimited number of arguments without the need to place them into an array, which is better than the way the PECL extension handles the function.
<?php
function harmonic () {
$num_args = func_num_args ();
for ($i = 0; $i < $num_args; $i++) {
$sum += 1 / func_get_arg ($i);
}
return $num_args / $sum;
}
echo harmonic (1, 2, 3, 4, 5);
echo harmonic (-1, 3, 4, 10293);
echo harmonic (-1, -2, -3, -4, -5);
?>