- floor: documentation ( source)
- pow: documentation ( source)
- sqrt: documentation ( source)
<?php
function echoFibonacciNumber(int $input)
{
if ($input < 0) {
echo "Invalid input";
}
if ($input === 0 || $input === 1) {
$output = $input;
} else {
$fi = (sqrt(5) + 1) / 2;
$output = floor(pow($fi, $input) / sqrt(5) + 1 / 2);
}
echo 'input: '.$input.', output: '.$output;
}
echo echoFibonacciNumber(6);