Home  >  Article  >  Backend Development  >  Problem with changing variable value in php reference address_PHP tutorial

Problem with changing variable value in php reference address_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:19:55670browse

Copy code The code is as follows:

$foo = 'Bob'; // Assign 'Bob' give $foo
$bar = &$foo; // reference $foo via $bar
echo $foo.'
';
$bar = "My name is $bar" ; // Modify the $bar variable
echo $bar.'
';
echo $foo.'
'; // The value of $foo is also modified
?>

Output:
Bob
My name is Bob
My name is Bob
We see that the original value was indeed modified, which happened after the reference After being assigned, but before being assigned, the original variable will not change.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325218.htmlTechArticleCopy the code as follows: ?php $foo = 'Bob'; // Assign 'Bob' to $foo $bar = // Reference $foo through $bar echo $foo.'br/'; $bar = "My name is $bar"; // Modify the $bar variable echo $bar....
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