text: Interquartile Range ( IQR ) | Function to give index of the median ; Function to calculate IQR ; Index of median of entire data ; Median of first half ; Median of second half ; IQR calculation ; Driver Function
code: < ? php function median ( $ a , $ l , $ r ) { $ n = $ r - $ l + 1 ; $ n = ( int ) ( ( $ n + 1 ) / 2 ) - 1 ; return $ n + $ l ; } function IQR ( $ a , $ n ) { sort ( $ a ) ; $ mid_index = median ( $ a , 0 , $ n ) ; $ Q1 = $ a [ median ( $ a , 0 , $ mid_index ) ] ; $ Q3 = $ a [ $ mid_index + median ( $ a , $ mid_index + 1 , $ n ) ] ; return ( $ Q3 - $ Q1 ) ; } $ a = array ( 1 , 19 , 7 , 6 , 5 , 9 , 12 , 27 , 18 , 2 , 15 ) ; $ n = count ( $ a ) ; echo IQR ( $ a , $ n ) ; ? >