A Boolean Matrix Question | PHP Code For A Boolean Matrix Question ; Initialize all values of row [ ] as 0 ; Initialize all values of col [ ] as 0 ; Store the rows and columns to be marked as 1 in row [ ] and col [ ] arrays respectively ; Modify the input matrix mat [ ] using the above constructed row [ ] and col [ ] arrays ; A utility function to print a 2D matrix ; Driver code
< ? php $ R = 3 ; $ C = 4 ; function modifyMatrix ( & $ mat ) { global $ R , $ C ; $ row = array ( ) ; $ col = array ( ) ; for ( $ i = 0 ; $ i < $ R ; $ i ++ ) { $ row [ $ i ] = 0 ; } for ( $ i = 0 ; $ i < $ C ; $ i ++ ) { $ col [ $ i ] = 0 ; } for ( $ i = 0 ; $ i < $ R ; $ i ++ ) { for ( $ j = 0 ; $ j < $ C ; $ j ++ ) { if ( $ mat [ $ i ] [ $ j ] == 1 ) { $ row [ $ i ] = 1 ; $ col [ $ j ] = 1 ; } } } for ( $ i = 0 ; $ i < $ R ; $ i ++ ) { for ( $ j = 0 ; $ j < $ C ; $ j ++ ) { if ( $ row [ $ i ] == 1 $ col [ $ j ] == 1 ) { $ mat [ $ i ] [ $ j ] = 1 ; } } } } function printMatrix ( & $ mat ) { global $ R , $ C ; for ( $ i = 0 ; $ i < $ R ; $ i ++ ) { for ( $ j = 0 ; $ j < $ C ; $ j ++ ) { echo $ mat [ $ i ] [ $ j ] . " " ; } echo " STRNEWLINE " ; } } $ mat = array ( array ( 1 , 0 , 0 , 1 ) , array ( 0 , 0 , 1 , 0 ) , array ( 0 , 0 , 0 , 0 ) ) ; echo " Input ▁ Matrix ▁ STRNEWLINE " ; printMatrix ( $ mat ) ; modifyMatrix ( $ mat ) ; echo " Matrix ▁ after ▁ modification ▁ STRNEWLINE " ; printMatrix ( $ mat ) ; ? >