Whether function parameter variables and global variables can have the same name
Can have the same name, if you want to use it inside the function To use global variables, you can declare them using the global keyword. At this time, the address of the variable points to the global variable.
<?php $a = 1; function A($a){ echo $a; global $a; echo $a; } A(2); ?>
Result:
2 1
Formal parameters:
The "formal parameter" in the custom function is called "form Parameter" is also called a dummy variable because it is not an actual variable. Actual parameters and formal parameters can have the same name.
Global variables:
Global variables can be created by an object function or anywhere in this program. Global variables can be referenced by all objects or functions in this program.
For more PHP related knowledge, please visit PHP Chinese website!
The above is the detailed content of Can function parameter variables and global variables have the same name?. For more information, please follow other related articles on the PHP Chinese website!