text: Program to print Fibonacci Triangle | function to fill Fibonacci Numbers in f [ ] ; 1 st and 2 nd number of the series are 1 and 1 ; Add the previous 2 numbers in the series and store it ; Fill Fibonacci numbers in f [ ] using fib ( ) . We need N = n * ( n + 1 ) / 2 Fibonacci numbers to make a triangle of height n ; To store next Fibonacci Number to print ; for loop to keep track of number of lines ; For loop to keep track of numbers in each line ; Driver code
code: < ? php function fib ( & $ f , $ N ) { $ f [ 1 ] = 1 ; $ f [ 2 ] = 1 ; for ( $ i = 3 ; $ i <= $ N ; $ i ++ ) $ f [ $ i ] = $ f [ $ i - 1 ] + $ f [ $ i - 2 ] ; } function fiboTriangle ( $ n ) { $ N = $ n * ( $ n + 1 ) / 2 ; $ f = array ( ) ; fib ( $ f , $ N ) ; $ fiboNum = 1 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { for ( $ j = 1 ; $ j <= $ i ; $ j ++ ) echo ( $ f [ $ fiboNum ++ ] . " ▁ " ) ; echo ( " STRNEWLINE " ) ; } } $ n = 5 ; fiboTriangle ( $ n ) ; ? >