I need to find the (next) Fibonacci number given by an integer N. So, let's say I have n = 13, and I need to print the next Fibonacci number, which is 21, but how to do it? How can I find the previous number that is summed to form it?
I mean, I could easily create a for / while loop that returns a Fibonacci sequence, but how can I find the next number by getting the previous one.
<?php
$n = 13;
while($n < 1000) {
$n = $x + $y;
echo($n."<br />");
$x = $y;
$y = $n;
}
?>
source
share