Reorder an array according to given indexes | Function to reorder elements of arr [ ] according to index [ ] ; $temp [ $n ] ; arr [ i ] should be present at index [ i ] index ; Copy temp [ ] to arr [ ] ; Driver Code
< ? php function reorder ( $ arr , $ index , $ n ) { for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ temp [ $ index [ $ i ] ] = $ arr [ $ i ] ; } for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ arr [ $ i ] = $ temp [ $ i ] ; $ index [ $ i ] = $ i ; } echo " Reordered ▁ array ▁ is : ▁ STRNEWLINE " ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { echo $ arr [ $ i ] . " " ; } echo " Modified Index array is : " for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { echo $ index [ $ i ] . " " ; } } $ arr = array ( 50 , 40 , 70 , 60 , 90 ) ; $ index = array ( 3 , 0 , 4 , 1 , 2 ) ; $ n = sizeof ( $ arr ) ; reorder ( $ arr , $ index , $ n ) ; ? >