Sorting array with reverse around middle | PHP program to find possibility to sort by multiple subarray reverse operarion ; making the copy of the original array ; sorting the copied array ; checking mirror image of elements of sorted copy array and equivalent element of original array ; Driver code
< ? php function ifPossible ( & $ arr , $ n ) { $ cp = array ( ) ; $ cp = $ arr ; sort ( $ cp ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( ! ( $ arr [ $ i ] == $ cp [ $ i ] ) && ! ( $ arr [ $ n - 1 - $ i ] == $ cp [ $ i ] ) ) return false ; } return true ; } $ arr = array ( 1 , 7 , 6 , 4 , 5 , 3 , 2 , 8 ) ; $ n = sizeof ( $ arr ) ; if ( ifPossible ( $ arr , $ n ) ) echo " Yes " ; else echo " No " ; ? >