Home > Backend Development > PHP Tutorial > 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?

小云云
Release: 2023-03-22 14:48:01
Original
2128 people have browsed it

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
Copy after login

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!

Related labels:
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