This article mainly introduces the implementation of the php printing and output board, and analyzes two different implementation methods in the form of examples, which has some reference value. If you need them, you can refer
This article mainly introduces the implementation of the php printing and output board, and analyzes two different implementation methods in the form of examples, which has some reference value. If you need them, you can refer
This article describes two ways to implement the php printing and output board. Share it with you for your reference. The specific implementation method is as follows:
Example 1: the code is as follows:
The Code is as follows:
<? Php
/**
* Change the color of every row and column
* String fun_table (int $ rows = 9, int $ cols = 9)
* $ Rows indicates that the number of rows must be an integer and must be between 1 and 20
* $ Cols indicates that the number of columns must be an integer and must be between 1 and 20.
*/
Function fun_table ($ rows = 9, $ cols = 9 ){
If ($ rows <1 | $ rows> 20 ){
Return "must be an integer and must be between 1 and 20 ";
}
If ($ cols <1 | $ cols> 20 ){
Return "must be an integer and must be between 1 and 20 ";
}
If ($ rows! = (Int) ($ rows )){
Return 'number of rows must be an integer ';
}
If ($ cols! = (Int) ($ cols )){
Return 'column number must be an integer ';
}
$ Str = "";
$ Str. ="
";For ($ I = 1; $ I <= $ rows; $ I ++ ){$ Str. ="
";For ($ j = 1; $ j <= $ cols; $ j ++ ){If ($ I + $ j) % 2 ){$ Str. ="
"; } Else { $ Str. =" |
| ";}}$ Str. ="
";}$ Str. ="
";
Return $ str;
}
Echo fun_table ();
?>
Example 2 simple implementation of the board-for Loop
To implement this board, first let's think about the board. There are a lot of squares, and then it is composed of black and white squares. First, let's draw the square. The Code is as follows:
The Code is as follows:
<? Php
Echo"
";For ($ I = 1; $ I <= 10; $ I ++ ){Echo"
";For ($ j = 1; $ j <= 10; $ j ++ ){Echo"
54im | ";}Echo"
";}Echo"
";
?>
After seeing the board above, consider the location of the black and white grids. There is a rule that we can find that the white grids on the horizontal and vertical bars are the base numbers and the black ones are even numbers, we can use the remainder method to determine the color of the cell to be displayed. The base cell is white and the even cell is black. The base + even number is even, so we can find the even number of cells (black), and the rest is the base cell (white). The Code is as follows:
The Code is as follows:
<? Php
/**
Implement the Board through the for loop and html
**/
Echo"
";For ($ I = 1; $ I <= 10; $ I ++ ){Echo"
";For ($ j = 1; $ j <= 10; $ j ++ ){If ($ I + $ j) % 2 ){Echo"
"; } Else { Echo" |
| ";}}Echo"
";}Echo"
";
?>
I hope this article will help you with php programming.
,