Program to check if a matrix is symmetric | Fills transpose of mat [ N ] [ N ] in tr [ N ] [ N ] ; Returns true if mat [ N ] [ N ] is symmetric , else false ; Driver code
< ? php for ( $ i = 0 ; $ i < $ N ; $ i ++ ) for ( $ j = 0 ; $ j < $ N ; $ j ++ ) if ( $ mat [ $ i ] [ $ j ] != $ tr [ $ i ] [ $ j ] ) return false ; return true ; } function isSymmetric ( $ mat , $ N ) { $ tr = array ( array ( ) ) ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) for ( $ j = 0 ; $ j < $ N ; $ j ++ ) $ tr [ $ i ] [ $ j ] = $ mat [ $ j ] [ $ i ] ; $ mat = array ( array ( 1 , 3 , 5 ) , array ( 3 , 2 , 4 ) , array ( 5 , 4 , 1 ) ) ; if ( isSymmetric ( $ mat , 3 ) ) echo " Yes " ; else echo " No " ; ? >