// harmonic value of N = (1 + 1/2 + 1/3 + ... 1/N)
function get_harmonic_value($n) {
if ($n == 1) {
return 1.0;
} else {
return 1.0 / $n + get_harmonic_value($n - 1);
}
}
$n = 6;
echo "Harmonic value: " . get_harmonic_value($n);
/*
run:
Harmonic value: 2.45
*/