PHP Learning Notes Function statement

Source: Internet
Author: User
Tags execution function definition functions return variable
Copy CodeThe code is 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);
?>


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.