Relationship between php parameters and real parameters

Source: Internet
Author: User
{Code ...} a1-b2-c3a2-b4-c6-num100 I come to the conclusion that the function is a one-to-one correspondence between the runtime parameters and the real parameters, but when I just want to pass $ num $ a $ c these three parameters do not want to pass $ B, it should input parameter myfunction (, 1, 3); running result: a1-b3-ca2-b5-c3...
Function myfunction ($ num, $ a, $ B, $ c) {echo "". $ a; echo "-B ". $ B; echo "-c ". $ c; echo"
"; $ B + = 2; $ c + = 3; $ a + = 1; echo" ". $ a; echo "-B ". $ B; echo "-c ". $ c; echo "-num ". $ num;} myfunction (, 1, 2, 3); running result:

A1-b2-c3
A2-b4-c6-num100

My inference is that the form parameters and real parameters of a function are in a one-to-one relationship at runtime.

However, if I only want to pass the $ num $ a $ c parameter and do not want to pass the $ B parameter

Myfunction (100,1, 3 );

Running result:
A1-b3-c
A2-b5-c3-num100

I want $ a = 1 $ c = 3 instead of $ B.

Reply content:
Function myfunction ($ num, $ a, $ B, $ c) {echo "". $ a; echo "-B ". $ B; echo "-c ". $ c; echo"
"; $ B + = 2; $ c + = 3; $ a + = 1; echo" ". $ a; echo "-B ". $ B; echo "-c ". $ c; echo "-num ". $ num;} myfunction (, 1, 2, 3); running result:

A1-b2-c3
A2-b4-c6-num100

My inference is that the form parameters and real parameters of a function are in a one-to-one relationship at runtime.

However, if I only want to pass the $ num $ a $ c parameter and do not want to pass the $ B parameter

Myfunction (100,1, 3 );

Running result:
A1-b3-c
A2-b5-c3-num100

I want $ a = 1 $ c = 3 instead of $ B.

Function parameters correspond to each other. If you do not want to pass a parameter, you can set the default value.

Function myfunction ($ num = 0, $ a = 0, $ B = 0, $ c = 0 ){...} // The Position of the called function must be myfunction (100 );

The topic is correct,Real parameters and form parameters are one-to-one mappings..
If you have three parameters, but you just want to pass the first and third parameters to the first and third parameters, the upstairs method is used;

Another is to put the least-used shape parameters at the end and assign the parameter a default value (This value depends on the business logic.In this way, only the first few parameters you want to pass can be passed when you pass the parameters, and the following parameters can be ignored.

When defining a function, the corresponding parameter is "form parameter". Here you are-function myfunction ($ num, $ a, $ B, $ c ){}.
When a function is called, the corresponding parameter is, real parameter, which corresponds to-myfunction (, 1, 2, 3 ).

It must be one-to-one.

When you write a function, you define the number of parameters and the number of parameters you need to write when calling the function. The principle is the same as that in the queuing system. You have an empty one in the middle, if you do not leave a position, it indicates that it is a vacancy. This will lead to a vacancy in the last position.

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.