To find the nth fibonacci number in PHP, we can use either recursion or dynamic programming approach.
Recursion method:
main.php170 chars7 lines
Dynamic Programming method:
main.php200 chars11 lines
In both methods, we return the nth fibonacci number. The recursion method uses function calling to calculate the fibonacci number which can be slower than the dynamic programming approach. The dynamic programming method stores previously computed numbers in an array making it a faster approach.
gistlibby LogSnag