Home > Backend Development > PHP Tutorial > Questions about changing the variable value of the php reference address

Questions about changing the variable value of the php reference address

WBOY
Release: 2016-07-25 09:03:22
Original
768 people have browsed it
  1. $foo = 'Bob'; // Assign 'Bob' to $foo
  2. $bar = &$foo; // Reference $foo through $bar
  3. echo $foo.'< ;br/>';
  4. $bar = "My name is $bar"; // Modify the $bar variable
  5. echo $bar.'
    ';
  6. echo $foo.'
    ?>
Copy the code

output: Bob My name is Bob My name is Bob

You can see that the original value is modified, which occurs after the reference and assignment, but the original variable will not change before it is assigned. Articles you may be interested in: Detailed introduction to php reference passing by value Understand the difference between passing by value and passing by reference in PHP through examples Look at the efficiency issues of php address reference through examples Quotes in PHP, "&" explanation



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