Queries for counts of array elements with values in given range | function to count elements within given range ; initialize result ; check if element is in range ; Driver Code ; Answer queries
< ? php function countInRange ( $ arr , $ n , $ x , $ y ) { $ count = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ arr [ $ i ] >= $ x && $ arr [ $ i ] <= $ y ) $ count ++ ; } return $ count ; } $ arr = array ( 1 , 3 , 4 , 9 , 10 , 3 ) ; $ n = count ( $ arr ) ; $ i = 1 ; $ j = 4 ; echo countInRange ( $ arr , $ n , $ i , $ j ) . " " ; $ i = 9 ; $ j = 12 ; echo countInRange ( $ arr , $ n , $ i , $ j ) . " " ; ? >