PHP Reference & symbol

Source: Internet
Author: User
I generally don't need to use php reference symbols when writing code. First of all, I don't know much about its usage. the C language is used to obtain the address, but PHP may be somewhat different, it is said to be a copy of the variable, that is, re-copy the same variable, such as $ a = & amp; $ B; then the variable a and variable B are complete... "/> <scripttype =" text/javascript "src =" http:

I generally don't need to use php reference symbols when writing code. First of all, I don't know much about its usage. the C language is used to obtain the address, but PHP may be somewhat different, it is said to be a copy of the variable, that is, re-copy the same variable, such

$ A = & $ B;

Then, variables a and B are completely equal, which is equivalent to $ a = $ B. is it necessary to write $ a = & $ B? This may also occupy more memory space.

 


Some people like to write it like this.

Function & f ($ arg1 ,..){

// Code body

}

In my opinion, writing in this way has no practical effect. Generally, the reference operators are written in the parameters of the function:

Function f (& $ x, & $ y ){

// The operations on $ x and $ y are assigned to $ x and $ y. if both $ x and $ y are returned outside the function;

// No return statement is required.

}

If function f is called, the calculated values of $ x and $ y can be obtained outside the function.

 


$ Total = array ();

$ Total_data = '';

F (& $ total, & $ total_data );

 


Echo $ total_data; // output the value of total_data after f function compute.

Var_dump ($ total); // The total value after f function calculation is output here.

 


These are my personal opinions. I hope you can correct them.

 

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.