Tail Recursion | A tail recursive function to calculate factorial ; A wrapper over factTR ; Driver program to test above function
< ? php function factTR ( $ n , $ a ) { if ( $ n == 0 ) return $ a ; return factTR ( $ n - 1 , $ n * $ a ) ; } function fact ( $ n ) { return factTR ( $ n , 1 ) ; } echo fact ( 5 ) ; ? >