Sum of all elements between k1 ' th ▁ and ▁ k2' th smallest elements | Returns sum between two kth smallest elements of the array ; Sort the given array ; Below code is equivalent to ; Driver program
< ? php function sumBetweenTwoKth ( $ arr , $ n , $ k1 , $ k2 ) { sort ( $ arr ) ; $ result = 0 ; for ( $ i = $ k1 ; $ i < $ k2 - 1 ; $ i ++ ) $ result += $ arr [ $ i ] ; return $ result ; } $ arr = array ( 20 , 8 , 22 , 4 , 12 , 10 , 14 ) ; $ k1 = 3 ; $ k2 = 6 ; $ n = count ( $ arr ) ; ; echo sumBetweenTwoKth ( $ arr , $ n , $ k1 , $ k2 ) ; ? >