Sort first half in ascending and second half in descending order | 1 | function to print half of the array in ascending order and the other half in descending order ; sorting the array ; printing first half in ascending order ; printing second half in descending order ; Driver code
< ? php function printOrder ( $ arr , $ n ) { sort ( $ arr ) ; for ( $ i = 0 ; $ i < $ n / 2 ; $ i ++ ) echo $ arr [ $ i ] . " ▁ " ; for ( $ j = $ n - 1 ; $ j >= $ n / 2 ; $ j -- ) echo $ arr [ $ j ] . " ▁ " ; } $ arr = array ( 5 , 4 , 6 , 2 , 1 , 3 , 8 , -1 ) ; $ n = sizeof ( $ arr ) ; printOrder ( $ arr , $ n ) ; ? >