Sum of Fibonacci Numbers | Computes value of first fibonacci numbers ; Initialize result ; Add remaining terms ; Driver Code
< ? php function calculateSum ( $ n ) { if ( $ n <= 0 ) return 0 ; $ fibo [ 0 ] = 0 ; $ fibo [ 1 ] = 1 ; $ sum = $ fibo [ 0 ] + $ fibo [ 1 ] ; for ( $ i = 2 ; $ i <= $ n ; $ i ++ ) { $ fibo [ $ i ] = $ fibo [ $ i - 1 ] + $ fibo [ $ i - 2 ] ; $ sum += $ fibo [ $ i ] ; } return $ sum ; } $ n = 4 ; echo " Sum ▁ of ▁ Fibonacci ▁ numbers ▁ is ▁ : ▁ " , calculateSum ( $ n ) , " STRNEWLINE " ; ? >