text: Sort the array in a given index range |  ; Function to sort the elements of the array from index a to index b ; Variables to store start and end of the index range ; Temporary array ; Sort the temporary array ; Modifying original array with temporary array elements ; Print the modified array ; Driver code ; length of the array
code: < ? php < ? php # PHP  program to sort the NEW_LINE # array  in a given index range NEW_LINE function partSort ( $ arr , $ N , $ a , $ b ) { $ l = min ( $ a , $ b ) ; $ r = max ( $ a , $ b ) ; $ temp = array ( ) ; $ j = 0 ; for ( $ i = $ l ; $ i <= $ r ; $ i ++ ) { $ temp [ $ j ] = $ arr [ $ i ] ; $ j ++ ; } sort ( $ temp ) ; $ j = 0 ; for ( $ i = $ l ; $ i <= $ r ; $ i ++ ) { $ arr [ $ i ] = $ temp [ $ j ] ; $ j ++ ; } for ( $ i = 0 ; $ i < $ N ; $ i ++ ) { echo $ arr [ $ i ] . " " ; } } $ arr = array ( 7 , 8 , 4 , 5 , 2 ) ; $ a = 1 ; $ b = 4 ; $ N = count ( $ arr ) ; partSort ( $ arr , $ N , $ a , $ b ) ; ? >