Program for Mean Absolute Deviation | Function to find mean of the array elements . ; Calculate sum of all elements . ; Function to find mean absolute deviation of given elements . ; Calculate the sum of absolute deviation about mean . ; Return mean absolute deviation about mean . ; Driver Code
< ? php function Mean ( $ arr , $ n ) { $ sum = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ sum = $ sum + $ arr [ $ i ] ; return $ sum / $ n ; } function meanAbsoluteDeviation ( $ arr , $ n ) { $ absSum = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ absSum = $ absSum + abs ( $ arr [ $ i ] - Mean ( $ arr , $ n ) ) ; return $ absSum / $ n ; } $ arr = array ( 10 , 15 , 15 , 17 , 18 , 21 ) ; $ n = sizeof ( $ arr ) ; echo meanAbsoluteDeviation ( $ arr , $ n ) ; ? >