Description of PHP Custom function

Source: Internet
Author: User

1, the function of the formal parameters can have more than one

2. The data type of the formal parameter can be any type supported by PHP.

3. The name of the function, like a custom variable, must begin with a letter or an underscore.

4, the function of the variable is a local variable, outside the function does not take effect.

5, the function name is case-insensitive.

6. When using global variables, you can use variables that are outside the function.

Examples of using global variables:

<?php
$a = 12;
Function abc () {
Global $a; Representation in the range of function ABC, using the $a outside of functions
$a +=45;
}
ABC ();
echo $a;
?>

Output: 57

7, in order to prevent the chaos of global variables, if you do not want to use a variable, you can use Unset ($var) to delete a variable.

<?php
$a = 12;
Function ABC ($a) {
unset ($a); Indicates that the $a is not used in the ABC function, and that a new definition is needed later.
$a = 45;
}
ABC ($a);
echo $a; Output 12
?>

8, in the PHP function, you can assign a default value for some parameters .

Cases:

<?php
Function ABC ($b, $a = 2) {
$res = $a + $b;
return $res;
}
$e = 70;
Echo ABC ($E). '||';
Echo ABC ($e, 90);
?>

Output: 72| | 160

9, php default value delivery, if you need to refer to (address) delivery, use the & variable name .

Cases:

<?php
$a = 213;
Function ABC (& $b) {
$b = 314;
}
ABC ($a);
echo $a; Output 314
?>

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.