Sort even and odd placed elements in increasing order | function to prin the odd and even indexed digits ; lists to store the odd and even positioned digits ; traverse through all the indexes in the integer ; if the digit is in odd_index position append it to odd_position list ; else append it to the even_position list ; print the elements in the list in sorted order ; Driver Code
< ? php function odd_even ( $ n ) { $ odd_indexes = array ( ) ; $ even_indexes = array ( ) ; for ( $ i = 0 ; $ i < sizeof ( $ n ) ; $ i ++ ) { if ( $ i % 2 == 0 ) array_push ( $ odd_indexes , $ n [ $ i ] ) ; else array_push ( $ even_indexes , $ n [ $ i ] ) ; } sort ( $ odd_indexes ) ; for ( $ i = 0 ; $ i < sizeof ( $ odd_indexes ) ; $ i ++ ) echo $ odd_indexes [ $ i ] , " ▁ " ; sort ( $ even_indexes ) ; for ( $ i = 0 ; $ i < sizeof ( $ even_indexes ) ; $ i ++ ) echo $ even_indexes [ $ i ] , " ▁ " ; } $ n = array ( 3 , 2 , 7 , 6 , 8 ) ; odd_even ( $ n ) ; ? >