PHP file reference with custom function

Source: Internet
Author: User

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:
    1. function: A keyword that defines a custom function;
    2. functionname: function names for custom functions;
    3. $param: Define the parameters of the function;
    4. DefaultValue: The default value of the function parameter;
    5. Function Body: function realization, function body is the statement block that executes when function is called;
    6. 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

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.