Home  >  Article  >  Backend Development  >  PHP reference calls

PHP reference calls

巴扎黑
巴扎黑Original
2016-11-24 13:10:23974browse

1.function test($arr){}
echo test(&$arr);
2.function test(&$arr){}
echo test($arr);
1 and 2 have the same effect.

3.function &test($arr){return $result;}
echo &test($a); is valid
echo test($a); returns a value, not a reference
Summary: only add before the method name when defining a method & When calling a method, a reference is returned only when & is added before the method name.

4.$a=$b;
When neither $a nor $b is reassigned, that is, when no writing operation occurs, the same as $a =&$b is the same, which is equivalent to assigning a reference.
Only when $a or $b changes, a copy of the value will be assigned to $a

Statement:
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