Copy Code code as follows:
<?php
/* Function Definition:
* 1. function is a named
* 2. Separate Code Snippets
* 3. Function to perform a specific task
* 4. And can return a value to the program that calls it
*
* Advantages of the function:
* 1. Improve the reusability of the program
* 2. Improve the maintainability of the program
* 3. Can improve development efficiency
* 4. Improve the reliability of the software
* 5. Complexity of control procedures
*
* Declaration of the function
* Function Functions name () {
*
* }
*
* Function name (parameter 1, parameter 2, parameter ...)
* {
* Function Body
* }
*
* Function functions name ()
* {
* Function body;
* return value;
* }
* Function name (parameter list ...)
* {
* Function body;
* Return value
* }
*
Attention
* One, the function must be called to execute, it can be invoked before the Declaration, or it can be invoked after the declaration
* Second, the function name and variables like, AAA BBB CCC AAABBBCCC (first word lowercase, after each word first letter capital)
* Third, the function cannot be duplicate when declaring
* Four, you can pass the parameters to the function, change the behavior of the function
* Formal parameters: When declaring a function, the argument is declared, the argument is a variable, and multiple arguments are used to separate
* Arguments: Passed to the parameter value (data, or variable) when the function is called
* Five, if there is no return value is called a procedure
* Vi. returning data by using the return statement
* Seven, function execution to return statement to end, do not write the code after this statement, you can also end the execution of the function
*
* Functions of the function name:
* 1. Call function, start execution function
* 2. You can pass data to a function
* 3. Function name is the value returned
*
*
*/
A function that outputs a table
function table ($tablename, $width, $row, $col)
{
Echo ' <table border= 1 "width=" '. $width. ' " align= "center" >;
Echo ' <caption>for ($i =0; $i < $row; $i + +)
{
Alternate color of interlaced
if ($i%2==0)
$BG = "#cccccc";
Else
$BG = "Yellow";
Echo ' <tr bgcolor= '. $bg. ' > '/output line
for ($j =0; $j < $col; $j + +)
{
Echo ' <td> '. ($i * $row + $j). ' <function table ($tablename, $width, $row, $col)
{
Echo ' <table border= 1 "width=" '. $width. ' " align= "center" >;
Echo ' <caption>for ($i =0; $i < $row; $i + +)
{
Alternate color of interlaced
if ($i%2==0)
$BG = "#cccccc";
Else
$BG = "Yellow";
Echo ' <tr bgcolor= '. $bg. ' > '/output line
for ($j =0; $j < $col; $j + +)
{
Echo ' <td> '. ($i * $row + $j). ' </td> ';
}
Echo ' </tr> ';
}
Echo ' </table> ';
}/td> ';
}
Echo ' </tr> ';
}
Echo ' </table> ';
}
Table ("Output table", 600,10,10);
Table ("Output table 2", 300,6,6);
Another way to output
function table2 ($tablename, $width, $row, $col)
{
$str = ' <table border= ' 1 "width=" ". $width. '" align= "center" >;
$str. = ' <caption>for ($i =0; $i < $row; $i + +)
{
Alternate color of interlaced
if ($i%2==0)
$BG = "#cccccc";
Else
$BG = "Yellow";
$str. = ' <tr bgcolor= '. $bg. ' > '/output line
for ($j =0; $j < $col; $j + +)
{
$str. = ' <td> '. ($i * $row + $j). ' </td> ';
}
$str. = ' </tr> ';
}
$str. = ' </table> ';
return $str;
}
echo table2 ("Direct output table", 400,15,15);
?>