Find nth Fibonacci number using Golden ratio | Approximate value of golden ratio ; Function to find nth Fibonacci number ; Fibonacci numbers for n < 6 ; Else start counting from 5 th term ; Driver Code
< ? php $ PHI = 1.6180339 ; function fib ( $ n ) { global $ PHI ; $ f = array ( 0 , 1 , 1 , 2 , 3 , 5 ) ; if ( $ n < 6 ) return $ f [ $ n ] ; $ t = 5 ; $ fn = 5 ; while ( $ t < $ n ) { $ fn = round ( $ fn * $ PHI ) ; $ t ++ ; } return $ fn ; } $ n = 9 ; echo $ n , " th ▁ Fibonacci ▁ Number ▁ = ▁ " , fib ( $ n ) , " STRNEWLINE " ; ? >