Home  >  Article  >  Backend Development  >  Function definition, role, local/global functions

Function definition, role, local/global functions

巴扎黑
巴扎黑Original
2016-12-01 09:38:151556browse

1. Function definition
A named piece of code that completes a specified task.
2. Format
function function name (parameter 1, parameter 2, parameter 3... )
{
Function body
return return value
}
Do not write the return value - process, write the return value - function
3. Write out the function of the function
How many parameters does the function have, what type is each parameter
What result does the function return after execution
4. Local variables
Variables declared inside the function
5. Global variables
Variables declared outside the function
To use it inside a function, you must use the keyword global, or generate a global array
function func()
{
global $a;
echo $a;
}

6. The & symbol represents the address
$a=100 ;
function func(&$a)
{
$a=999;
}
echo $a. “
”;

7. Static variable, shared between all calls to the function
function func()
{
static $a = 0;
echo $a. “
”;
$a++;
}
func();
8. Function_exists to detect whether a function exists
echo function_exists(“test1”);
9. Variables in PHP are case-sensitive, and others are not. For example, the func above can be written as Func, fUnc, etc.
Global variables, local variables, value transfer, address transfer, and other applications of functions

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn