Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the parameter assignments of the php function

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "what are the parameter assignments of the php function". The editor shows you the operation process through the actual case, the operation method is simple and fast, and the practicality is strong. I hope this article "what are the parameter assignments of the php function" can help you solve the problem.

Php function parameter assignment has three kinds: 1, value transfer assignment, the value of the argument will be copied and then assigned to the function parameter; 2, reference transfer assignment, a copy of the memory address of the parameter, and then passed to the function parameter, and then the actual parameter value will be assigned to the parameter; 3, directly assign the default value to the function parameter, syntax "function name (parameter variable = 'value')".

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

There are three parameter assignments for the php function:

1. Value transfer assignment

2. Reference transfer assignment

3. Default parameter values

Let's give you a detailed introduction.

1. Value transfer assignment

Value passing is the default way for functions to pass values in PHP, also known as "copy passing values".

As the name implies, the method of value assignment will copy the value of the argument and pass it to the parameter of the function, so the value of the operation parameter in the function will not affect the argument outside the function.

So if you don't want the function to change the value of the argument, you can pass it by value.

Example:

2. Reference transfer assignment

The reference passing of the parameter is to make a copy of the memory address of the argument, then pass it to the parameter of the function, and then assign the value of the parameter to the parameter.

Both the argument and the parameter point to the same memory address, so the operation of the function on the parameter will affect the argument outside the function.

Passing by reference is passing the memory address of the argument to the formal parameter of the function. So the argument and the parameter point to the same memory address. At this point, all operations inside the function will affect the value of the arguments outside the function. References are passed by adding an & symbol to the value, as shown below:

Function name (& Parameter 1, & Parameter 2,..., & Parameter 3) {.}

Example:

3. Default parameter values

The default parameter is to specify a default value for one or more formal parameters of the function. If the corresponding value is not passed in when the function is called, then the function will use this default value, which can avoid errors without parameters when calling. It can also make some programs seem more reasonable. If the corresponding parameter is passed in, the default value is replaced.

The default parameters of the function are as follows:

Function name ($str = 'default', $url) {echo $str;}

The = connection is required between the default values for shape participation.

Example:

The default parameter can also be multiple, and the default parameter must be placed to the right of the non-default parameter, and the value of the specified default parameter must be a specific value, such as a number, string, not a variable.

This is the end of the content about "what are the parameter assignments of the php function". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report