Php learning notes function declaration. Copy the code as follows :? Php * function definition: * 1. the function is named * 2. independent code segment * 3. the Function executes a specific task * 4. it can return a value to the program that calls it.
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 );
?>
The http://www.bkjia.com/PHPjc/323569.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/323569.htmlTechArticle code is as follows :? Php/* function definition: * 1. the function is named * 2. independent code segment * 3. function execution specific task * 4. you can return a value for the program that calls it...