Copy CodeThe code is as follows:
/* Function Definition:
* 1. The function is a named
* 2. Separate Code Snippets
* 3. Functions perform specific tasks
* 4. And can return a value to the program that called 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 functions
* Function name () {
*
* }
*
* Function name (parameter 1, parameter 2, parameter ...)
* {
* Function Body
* }
*
* Function name ()
* {
* Function body;
* return value;
* }
* Function name (parameter list ...)
* {
* Function body;
* Return value
* }
*
Note
* One, the function must be called to execute, can be called before the declaration, or can be called after the declaration
* Second, function name and variable, AAA BBB CCC AAABBBCCC (the first word lowercase, the first letter of each word capitalized)
* Third, function can not duplicate the name when declaring
* Four, you can change the behavior of the function by passing parameters to the function
* Formal parameters: When declaring a function, the arguments are declared, arguments are variables, multiple parameters are used, separate
* Arguments: Passed to a parameter value (data, or variable) when calling a function
* Five, if no return value is called process
* Vi. returning data by using the return statement
* Seven, the function execution to the return statement is finished, do not write the code after this statement, you can also use return to end the execution of the function
*
* Function Name:
* 1. Call the function and start executing the function
* 2. You can pass data to a function
* 3. Function name is the value returned
*
*
*/
A function of the output table
function table ($tablename, $width, $row, $col)
{
Echo '
';Echo '
'. $tablename. '
';for ($i =0; $i < $row; $i + +){Interlaced color changeif ($i%2==0)$BG = "#cccccc";Else$BG = "Yellow";Echo '
';//output line for ($j =0; $j < $col; $j + +) {echo '
'. ($i * $row + $j). ' { Echo '
'; Echo '
'. $tablename. '
'; for ($i =0; $i < $row; $i + +) {//Interlaced color change if ($i%2==0) $BG = "#cccccc"; else $BG = "yellow"; Echo '
';//output line for ($j =0; $j < $col; $j + +) {echo '
'. ($i * $row + $j). ' | '; } Echo '
'; } Echo '
'; }/td> '; } Echo ' |
'; } Echo '
';
}
Table ("Output table", 600,10,10);
Table ("Output table 2", 300,6,6);
Another way to output
function table2 ($tablename, $width, $row, $col)
{
$str = '
'; $str. = '
'. $tablename. '
'; for ($i =0; $i < $row; $i + +) {//Interlaced color change if ($i%2==0) $BG = "#cccccc"; else $BG = "yellow"; $str. = '
';//output line for ($j =0; $j < $col; $j + +) {$str. = '
'. ($i * $row + $j). ' | '; } $str. = '
'; } $str. = '
';
return $str;
}
echo table2 ("Direct Output form", 400,15,15);
?>
The above describes the Photoshop Learning Web PHP learning Note Function statement, including the Photoshop Learning Web content, I hope the PHP tutorial interested in a friend helpful.