The function must be called before execution. It can be called before declaration or after declaration.
The function must be called before execution. It can be called before declaration or after declaration.
The Code is as follows:
/* Function Definition:
* 1. The function is named
* 2. Independent code segments
* 3. The function executes a specific task.
* 4. You can return a value to the program that calls it.
*
* Advantages of functions:
* 1. Improve program reusability
* 2. Improve the maintainability of the program
* 3. Improved development efficiency
* 4. Improve Software Reliability
* 5. Complexity of the control program
*
* Function declaration
* 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:
* 1. functions must be called before execution. They can be called before declaration or after declaration.
* 2. The function name is the same as the variable name. aaa bbb ccc aaaBbbCcc (the first word is lowercase, And the last letter is uppercase)
* 3. The function name cannot be repeated during declaration.
* 4. You can change the function behavior by passing parameters to the function.
* Form parameters: When declaring a function, the declared parameters are variables. Multiple parameters are used and separated.
* Real parameter: The parameter value (data or variable) is passed when a function is called)
* 5. A process is called if no return value exists.
* 6. return data using the return Statement
* 7. When the function is executed, the return statement ends. You can use return to end the function execution instead of writing code after this statement.
*
* Function Name:
* 1. Call the function and start executing the function.
* 2. data can be transferred to the function.
* 3. The function name is the returned value.
*
*
*/
// Function of an output table
Function table ($ tablename, $ width, $ row, $ col)
{
Echo'
';Echo'
'. $ Tablename .'
';For ($ I = 0; $ I <$ row; $ I ++){// Change the color of the lineIf ($ I % 2 = 0)$ Bg = "# cccccc ";Else$ Bg = "yellow ";Echo'
'; // Output lineFor ($ j = 0; $ j <$ col; $ j ++){Echo'
'. ($ I * $ row + $ j ).' {
Echo'
';Echo'
'. $ Tablename .'
';For ($ I = 0; $ I <$ row; $ I ++){// Change the color of the lineIf ($ I % 2 = 0)$ Bg = "# cccccc ";Else$ Bg = "yellow ";Echo'
'; // Output lineFor ($ j = 0; $ j <$ col; $ j ++){Echo'
| '. ($ I * $ row + $ j ).' | ';}Echo'
';}Echo'
';
}/Td> ';
}
Echo' |
';}Echo'
';
}
Table ("output table", 10 );
Table ("output table 2", 6 );
// Another Output Method
Function table2 ($ tablename, $ width, $ row, $ col)
{
$ Str ='
';$ Str. ='
'. $ Tablename .'
';For ($ I = 0; $ I <$ row; $ I ++){// Change the color of the lineIf ($ I % 2 = 0)$ Bg = "# cccccc ";Else$ Bg = "yellow ";$ Str. ='
'; // Output lineFor ($ j = 0; $ j <$ col; $ j ++){$ Str. ='
| '. ($ I * $ row + $ j ).' | ';}$ Str. ='
';}$ Str. ='
';
Return $ str;
}
Echo table2 ("direct output table", 15, 15 );
?>