Photoshop Learning Tutorial PHP learning Function Courseware

Source: Internet
Author: User
Code reuse
Include ()
Require ()
Both of these functions are used to refer to a file, except that the include () generates a warning when processing fails and require () is a dense error
Include_once ()
Require_once ()
These two functions are the same as the include () and require (), except that include_once and require_once can only be referenced once
Custom functions
Custom functions are declared with function ().
Advantages of the function:
Complexity of Control program design
Improve the reliability of software
Improve the efficiency of software development
Improved maintainability of software
Improve the reusability of programs
Syntax format for custom functions:
Function name (parameter 1, parameter 2) {
The contents of the program are described;
Return
}
Function name (parameter 1, parameter 2);
return value;//return value can also be an expression
Custom function names are case insensitive. You cannot use a declared function when naming a function, or a function name built in PHP.
Determine if a function exists: function_exists (function name);
Range of variables
The visibility of variables refers to the scope of variables in the program.
In general, variables are divided into two types: local variables and global variables
Local variables:
A variable declared in a function is a local variable, and the variable can be used only within the scope of the function. If another program needs to invoke the value of the variable locally, it must be passed back to the main program block for subsequent processing through the "return" instruction.
Global variables:
A variable declared outside the scope of a function is a global variable. Because a function can be treated as a separate program fragment, local variables cover the visibility of global variables and therefore cannot be called directly using global variables in functions.
To use global variables in a function, you must define the target variable with the global keyword to tell the function body that the variable is global.
You can also use a predefined array of global variables, $globals. This is a special variable that is created automatically when the program is run.
echo $GLOBALS ["A"];
by unset ($var) You can manually delete variables, which are freed in memory and not in the global scope.
Using require with include does not affect scopes
static variables
Declares that the function variable is static (static).
A static variable is shared among all calls to the function and is initialized only when the function is first called during the execution of the script. To declare a function variable to be static, use the keyword static. Typically, the first time a static variable is used, it is given an initial value.
Passing of parameters
Pass parameters by value:
The parent program passes the specified value or variable directly to the function's use. Because the values or variables passed, and the values in the function are stored in different memory chunks, the function does not have a direct effect on the parent program when any changes are made to the imported values.
Pass parameters by address (implemented with the "&" symbol)
Rather than passing the pattern by value, the specified numeric value or target variable in the parent program is not passed to the function, but instead the memory chunk relative address of the value or variable is imported into the function. Therefore, when there is any change in the function, the parent program is affected by the value.
Default parameters
The default parameter must be listed after all parameters that do not have a default value.
function fun_sum ($a, $b =0, $c =0) {
Return $a + $b + $c;
}
echo Fun_sum (10,20);
echo Fun_sum (10,20,30);
0 is the default parameter
Any number of parameter lists
Func_get_args ()//Returns an array containing all the parameters
Func_num_args ()//total number of parameters returned
Func_get_arg ()//receives a numeric parameter, returns the specified parameter to find the value by subscript
function foo ()
{
$numargs = Func_num_args ();
echo "Number of arguments: $numargs
\ n ";
if ($numargs >= 2) {
echo "Second argument is:". Func_get_arg (1). "
\ n ";
}
$arg _list = Func_get_args ();
for ($i = 0; $i < $numargs; $i + +) {
echo "Argument $i is:". $arg _list[$i]. "
\ n ";
}
}
Foo (1, 2, 3);
Output result: Number of Arguments:3
Second argument Is:2
Argument 0 is:1
Argument 1 Is:2
Argument 2 Is:3
Variable function
This means that if a variable name has parentheses after it, PHP will look for a function with the same name as the value of the variable and will attempt to execute it. This can be used to implement callback functions, function tables, and so on, among other things.
Recursive invocation
The so-called function recursive invocation is that the function can invoke execution itself in the execution narrative of its declaration.
Usually in this type of function will be attached to a conditional judgment narration, in order to determine whether the need to perform recursive calls, and under certain conditions to terminate the function of the recursive call action, the current process of the main control to return to the previous layer of function execution. Therefore, when a function that executes a recursive call does not have an additional condition to judge the narrative, it may cause an infinite loop error condition.
The greatest benefit of recursive function invocation is that it can be used to simplify the process of repeatedly calling programs, and can perform some complex operations with this feature.
This courseware is Phpchina teaching courseware
1210491967_9664e02c.rar

The above describes the Photoshop Learning Tutorial PHP learning function Courseware, including the Photoshop Learning tutorial content, I hope to be interested in PHP tutorial friends helpful.

  • 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.