Row | PHP program to find common elements in two diagonals . ; Returns count of row wise same elements in two diagonals of mat [ n ] [ n ] ; Driver Code
< ? php $ MAX = 100 ; function countCommon ( $ mat , $ n ) { global $ MAX ; $ res = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) if ( $ mat [ $ i ] [ $ i ] == $ mat [ $ i ] [ $ n - $ i - 1 ] ) $ res ++ ; return $ res ; } $ mat = array ( array ( 1 , 2 , 3 ) , array ( 4 , 5 , 6 ) , array ( 7 , 8 , 9 ) ) ; echo countCommon ( $ mat , 3 ) ; ? >