Sum of minimum element of all subarrays of a sorted array | Function to find the sum of minimum of all subarrays ; Driver code
< ? php function findMinSum ( $ arr , $ n ) { $ sum = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ sum += $ arr [ $ i ] * ( $ n - $ i ) ; return $ sum ; } $ arr = array ( 3 , 5 , 7 , 8 ) ; $ n = count ( $ arr ) ; echo findMinSum ( $ arr , $ n ) ; ? >