Find sum of factorials in an array | Function to return the factorial of n ; Function to return the sum of factorials of the array elements ; To store the required sum ; Add factorial of all the elements ; Driver code
< ? php function factorial ( $ n ) { $ f = 1 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { $ f *= $ i ; } return $ f ; } function sumFactorial ( $ arr , $ n ) { $ s = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ s += factorial ( $ arr [ $ i ] ) ; } return $ s ; } $ arr = array ( 7 , 3 , 5 , 4 , 8 ) ; $ n = sizeof ( $ arr ) ; echo sumFactorial ( $ arr , $ n ) ; ? >