References between PHP files
- Include language structure
- Format: mixed include (string resource); Load a resource file resource into the current PHP program;
- When a resource resource is a resource on the Internet, the option Allow_url_include in profile php.ini needs to be set to ON (Allow_url_include = ON).
- Require language structure
- Basically the same as include;
- The difference: When using include, if an error occurs or the reference file is not found, continue to execute the following statement;
When using require, the program runs if an error occurs or the reference file is not found.
- Include_once and require_once language structure
- Format: Mixed include_once (string resource); Loading a resource file resource into the current PHP program, avoiding multiple references to the same PHP file and causing the function or variable to be duplicated;
- Returns False if the resource file resource is not found and the file is first loaded, returns an integer of 1, found and loaded, returns TRUE.
Custom functions
function functionname ($param 1$param 2$param 3$paramn= DefaultValue) { function body return value;}
Syntax format:
- function: A keyword that defines a custom function;
- functionname: function names for custom functions;
- $param: Define the parameters of the function;
- DefaultValue: The default value of the function parameter;
- Function Body: function realization, function body is the statement block that executes when function is called;
- Return: The execution of this function is immediately terminated when the program runs to return.
Parameter assignment methods for custom functions
- Transfer value Assignment
- Transfer Address Assignment value
- Append a "&" character to the function's parameter name to implement the address assignment, for example:& $value;
- When using this method, the value passed to the function cannot be a constant;
Global keyword
- Add the keyword Global (example: Global $value) before the defined variable name to change the local variable to a global variable;
- Note: While using global to define global variables within a function, you cannot assign a value to the variable using an assignment statement.
Static keyword
- With the static keyword in front of the variable, you can keep the variables in the function body from this call until the next call;
- Note: Static variables are only valid in the current execution of the PHP program, and refreshing the page will start all over again.
PHP file reference with custom function