text: Sum of all Subarrays | Set 1 | function compute sum all sub - array ; computing sum of subarray using formula ; return all subarray sum ; Driver Code
code: < ? php function SubArraySum ( $ arr , $ n ) { $ result = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ result += ( $ arr [ $ i ] * ( $ i + 1 ) * ( $ n - $ i ) ) ; return $ result ; } $ arr = array ( 1 , 2 , 3 ) ; $ n = sizeof ( $ arr ) ; echo " Sum ▁ of ▁ SubArray ▁ : ▁ " , SubArraySum ( $ arr , $ n ) , " STRNEWLINE " ; #This  code is contributed by aj_36 NEW_LINE ? >