Trinomial Triangle | Function to find the trinomial triangle value . ; base case ; base case ; recursive step . ; Function to print Trinomial Triangle of height n . ; printing n rows . ; printing first half of triangle ; printing second half of triangle . ; Driver Code
< ? php function TrinomialValue ( $ n , $ k ) { if ( $ n == 0 && $ k == 0 ) return 1 ; if ( $ k < - $ n $ k > $ n ) return 0 ; return TrinomialValue ( $ n - 1 , $ k - 1 ) + TrinomialValue ( $ n - 1 , $ k ) + TrinomialValue ( $ n - 1 , $ k + 1 ) ; } function printTrinomial ( $ n ) { for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { for ( $ j = - $ i ; $ j <= 0 ; $ j ++ ) echo TrinomialValue ( $ i , $ j ) , " ▁ " ; for ( $ j = 1 ; $ j <= $ i ; $ j ++ ) echo TrinomialValue ( $ i , $ j ) , " ▁ " ; echo " STRNEWLINE " ; } } $ n = 4 ; printTrinomial ( $ n ) ; ? >