Find a specific pair in Matrix | A Naive method to find maximum value of $mat [ d ] [ e ] - ma [ a ] [ b ] such that $d > $a and $e > $b ; The function returns maximum value A ( d , e ) - A ( a , b ) over all choices of indexes such that both $d > $a and $e > $b . ; stores maximum value ; Consider all possible pairs $mat [ $a ] [ $b ] and $mat [ $d ] [ $e ] ; Driver Code
< ? php $ N = 5 ; function findMaxValue ( & $ mat ) { global $ N ; $ maxValue = PHP_INT_MIN ; for ( $ a = 0 ; $ a < $ N - 1 ; $ a ++ ) for ( $ b = 0 ; $ b < $ N - 1 ; $ b ++ ) for ( $ d = $ a + 1 ; $ d < $ N ; $ d ++ ) for ( $ e = $ b + 1 ; $ e < $ N ; $ e ++ ) if ( $ maxValue < ( $ mat [ $ d ] [ $ e ] - $ mat [ $ a ] [ $ b ] ) ) $ maxValue = $ mat [ $ d ] [ $ e ] - $ mat [ $ a ] [ $ b ] ; return $ maxValue ; } $ mat = array ( array ( 1 , 2 , -1 , -4 , -20 ) , array ( -8 , -3 , 4 , 2 , 1 ) , array ( 3 , 8 , 6 , 1 , 3 ) , array ( -4 , -1 , 1 , 7 , -6 ) , array ( 0 , -4 , 10 , -5 , 1 ) ) ; echo " Maximum ▁ Value ▁ is ▁ " . findMaxValue ( $ mat ) ; ? >