Php learning notes function declaration

Source: Internet
Author: User

Copy codeThe Code is as follows:
<? Php
/* 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 '<table border = "1" width = "'. $ width. '" align = "center"> ';
Echo '<caption> For ($ I = 0; $ I <$ row; $ I ++)
{
// Change the color of the line
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 ++)
{
// Change the color of the line
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", 10 );
Table ("output table 2", 6 );

// Another Output Method
Function table2 ($ tablename, $ width, $ row, $ col)
{
$ Str = '<table border = "1" width = "'. $ width. '" align = "center"> ';
$ Str. = '<caption> For ($ I = 0; $ I <$ row; $ I ++)
{
// Change the color of the line
If ($ I % 2 = 0)
$ Bg = "# cccccc ";
Else
$ Bg = "yellow ";
$ Str. = '<tr bgColor = "'. $ bg. '">'; // output row
For ($ j = 0; $ j <$ col; $ j ++)
{
$ Str. = '<td>'. ($ I * $ row + $ j). '</td> ';
}
$ Str. = '</tr> ';

}
$ Str. = '</table> ';

Return $ str;
}

Echo table2 ("direct output table", 15, 15 );
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.