Find the original matrix when largest element in a row and a column are given | PHP implementation of the approach ; Function that prints the original matrix ; Iterate in the row ; Iterate in the column ; If previously existed an element ; Driver code
< ? php $ N = 3 ; $ M = 7 ; function printOriginalMatrix ( $ a , $ b , $ mat ) { for ( $ i = 0 ; $ i < $ GLOBALS [ ' N ' ] ; $ i ++ ) { for ( $ j = 0 ; $ j < $ GLOBALS [ ' M ' ] ; $ j ++ ) { if ( $ mat [ $ i ] [ $ j ] == 1 ) echo min ( $ a [ $ i ] , $ b [ $ j ] ) . " ▁ " ; else echo "0" . " ▁ " ; } echo " \r STRNEWLINE " ; } } $ a = array ( 2 , 1 , 3 ) ; $ b = array ( 2 , 3 , 0 , 0 , 2 , 0 , 1 ) ; $ mat = array ( array ( 1 , 0 , 0 , 0 , 1 , 0 , 0 ) , array ( 0 , 0 , 0 , 0 , 0 , 0 , 1 ) , array ( 1 , 1 , 0 , 0 , 0 , 0 , 0 ) ) ; printOriginalMatrix ( $ a , $ b , $ mat ) ; ? >