Interchange elements of first and last rows in matrix | PHP code to swap the element of first and last row and display the result ; swapping of element between first and last rows ; input in the array ; printing the interchanged matrix
< ? php $ n = 4 ; function interchangeFirstLast ( & $ m ) { global $ n ; $ rows = $ n ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ t = $ m [ 0 ] [ $ i ] ; $ m [ 0 ] [ $ i ] = $ m [ $ rows - 1 ] [ $ i ] ; $ m [ $ rows - 1 ] [ $ i ] = $ t ; } } $ m = array ( array ( 8 , 9 , 7 , 6 ) , array ( 4 , 7 , 6 , 5 ) , array ( 3 , 2 , 1 , 8 ) , array ( 9 , 9 , 7 , 7 ) ) ; interchangeFirstLast ( $ m ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { for ( $ j = 0 ; $ j < $ n ; $ j ++ ) echo $ m [ $ i ] [ $ j ] . " ▁ " ; echo " STRNEWLINE " ; } ? >