Mirror of matrix across diagonal | Efficient PHP program to find mirror of matrix across diagonal . ; traverse a matrix and swap mat [ i ] [ j ] with mat [ j ] [ i ] ; Utility function to print a matrix ; Driver Code
< ? php function imageSwap ( & $ mat , $ n ) { for ( $ i = 0 ; $ i < $ n ; $ i ++ ) for ( $ j = 0 ; $ j <= $ i ; $ j ++ ) $ mat [ $ i ] [ $ j ] = $ mat [ $ i ] [ $ j ] + $ mat [ $ j ] [ $ i ] - ( $ mat [ $ j ] [ $ i ] = $ mat [ $ i ] [ $ j ] ) ; } function printMatrix ( & $ mat , $ n ) { for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { for ( $ j = 0 ; $ j < $ n ; $ j ++ ) { echo ( $ mat [ $ i ] [ $ j ] ) ; echo ( " ▁ " ) ; } echo ( " STRNEWLINE " ) ; } } $ mat = array ( array ( 1 , 2 , 3 , 4 ) , array ( 5 , 6 , 7 , 8 ) , array ( 9 , 10 , 11 , 12 ) , array ( 13 , 14 , 15 , 16 ) ) ; $ n = 4 ; imageSwap ( $ mat , $ n ) ; printMatrix ( $ mat , $ n ) ; ? >