Php core syntax-use of functions

Source: Internet
Author: User
Function: a set of code with a certain function. When this function is required, we can execute (call) the corresponding function. Structured programming encapsulates all functions into independent structures. Abstract programming. Define the function each time you use the function. Turn the function into a tool now, however... "> <LINKhref =" http://www.php100.com//statics/style/headflo

 

Function: a set of code with a certain function. When this function is required, we can execute (call) the corresponding function. Structured programming encapsulates all functions into independent structures. Abstract programming. Define the function each time you use the function. Convert the function into a tool, and use the tool. The function must be defined before use. The functions are defined as system functions and user functions. Basic syntax of a Function: syntax for defining a Function: Function name (parameter) {Function body} syntax for calling a Function: Function name (parameter passed to the Function ). the basic component of a function: the identifier of a function. for details about the data when a function is executed, see the function body (code block for implementing the function, A feedback) definition: Call: for the function name section, refer to the variable name naming rules, but the function name is case insensitive. However, we recommend that you define how to call the API. Function parameters: formal parameters: the parameters used by a function in definition are called formal parameters. The format parameter has no specific value. A value is assigned only when it is called. Parameter for short. Actual parameters: when a function is called, it passes in meaningful parameters according to the rules of formal parameters. In this case, it is called a real parameter. In general, when a formal parameter is called differently, it is a value transfer method to obtain the actual parameter value. In contrast to value transfer, there is also reference transfer. If parameter reference is required, you must add a reference symbol before the parameter &. when max3 is called: When we modify the values of the x, y, and z variables in the function body, it will have different effects on a, B, and c: if a parameter occupies a lot of resources, do we use a value or reference to improve efficiency? Reference. It is not required that all parameters are or are not a certain transmission method. you can set them separately on the parameters. Default value of a parameter: when defining a function, we can set the default value as a function parameter. In this way, when we call a function, if data is not transmitted for this parameter, the default value is used instead. Function return value: the return value is indicated by the return statement. Each function is usually required to return values, but the syntax still does not return values. When the function is executed to the return statement, the function stops running. This means that all function bodies after the return statement do not need to be executed again. How many return values can a function return? One. Can there be several return statements? Multiple. A function can only return one value. what if a function requires that two data values be returned? How can a function affect two values at the same time? Package two values into a set type of data. Using parameter reference transfer, many Php functions use reference transfer to process multiple return values for one function: Tip: If the parameter is passed as a reference, A variable must be passed. Because only variables can be referenced and passed. Scope problem: the scope of the variable. only functions can divide the scope. Code that can be used when a variable is defined. The scope of a variable. You need to know the scope of php: global scope. The function is out of the global scope. Variables defined in the global scope are visible in the global scope. Local scope. In a function, a function forms a local scope. Variables defined in the local scope are locally visible. Super Global: either within the function or outside the function. Access global scope variables in a local scope. You need to use the global keyword to declare a global variable in a local scope. In addition to the global keyword, the following method is also available: Php will put all the defined global variables into an array. This array is $ GLOBALS (Super Global ). Each element of GLOBALS is a global variable. the subscript of an element is the name of a global variable, and the value of an element is the value of a variable. Local scopes are generated when a function is called. At the end of the function, the scope generated by the function disappears, and all variables in the scope should disappear. The global scope is generated when the php script runs. The script disappears at the end of running. Variables in the global scope should also disappear. In php, static variables with local scopes are supported. The scope also belongs to a local scope. However, because the variable is static, the static variable will not disappear after the function is run and will keep the original processed value. Static local variables take effect only within the scope of the current function. Summary: general global: Common part outside the function: Super Global in the function: static part in all places: in the current function, the function does not disappear after running. It can be used again in the next call. What is the role of using global: global $ GLOBALS [] job parameter reference transfer in a local environment? After completing the Yang Hui triangle: the first column and the diagonal line are both 1. In addition, the value is = the value on the top of the head + the value on the left shoulder. 111121133114641151010511615201561 is defined as a function Yanghui (7). the parameter is the number of rows. Tip: using double loops and arrays, you can print stars and define a function xingxing (4 );

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.