Home  >  Article  >  Backend Development  >  What is the difference between normal pass-by-value and pass-by-reference in php functions?

What is the difference between normal pass-by-value and pass-by-reference in php functions?

小云云
小云云Original
2018-03-28 14:28:102020browse

This article mainly shares with you the difference between ordinary value-passing and reference-passing in PHP functions. We will share with you a combination of text and code. Hope it helps everyone.

  • Pass by reference

    • Variable, for example foo($a)

    • New Statements such as foo(new foobar())

    • References returned from functions

    • You can pass a variable to a function by reference, In this way, the function can modify the value of its parameters

    • The following content can be passed by reference

  • Normal value passing

    Functions cannot modify the value of variables

<?phpfunction foo(&$var){
    $var++;
}function foo1($var){
    $var++;
}$a = 5;echo $a;echo "<br>";
foo($a);echo $a;echo "<br>";$b = 10;echo $b;echo "<br>";
foo1($b);echo $b;


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

输出561010

Related recommendations:

Detailed explanation of the difference between passing by value and passing by reference in php

The above is the detailed content of What is the difference between normal pass-by-value and pass-by-reference in php functions?. For more information, please follow other related articles on the PHP Chinese website!

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