Home > Backend Development > PHP Tutorial > Discussing the PHP Reference & Symbol_PHP Tutorial

Discussing the PHP Reference & Symbol_PHP Tutorial

WBOY
Release: 2016-07-14 10:09:59
Original
866 people have browsed it

I generally don’t use PHP’s reference symbols when writing code. First of all, I don’t know how to use it. C language is used to get addresses, but there may be some differences in PHP. It is said to be a copy of a variable, or Just copy the same variable again, such as

$a=&$b;

Then variable a and variable b are completely equal, completely equivalent to $a=$b; so is it necessary to write $a=&$b? This may also take up more memory space


Some people like to write like this

function &f($arg1,..) {

//code body

                                                                                 }

I think writing like this has no practical effect. Generally, the reference operator is written in the parameters of the function:

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

// Here is the operation of $ x and $ y, that is, assigning value to $ x and $ y.

// No need to use the RETURN statement

                                                                       }

Then if function f is called, the calculated values ​​of $x and $y can be obtained directly outside the function.

$total=array();

$total_data='';

f(&$total,&$total_data);

echo $total_data; //The value of total_data calculated by the f function is output here

var_dump($total);//The value of total calculated by the f function is output here

The above is my personal opinion, I hope everyone can correct me.


http://www.bkjia.com/PHPjc/477581.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477581.htmlTechArticleI generally don’t use the reference symbols in PHP when writing code. First of all, I don’t know much about its usage. C The language is used to get the address, but it may be different in PHP. It is said that it is a variable...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template