mysql - explain this OOPS cpnecpt in php ..i dont get the 2nd echo $a becomes 30 -


why $a in 2nd echo becomes 30 when should 20


 function &ref_return() {             global $a;             $a = $a * 2;             return $a;         }         $a = 10;         $b =& ref_return();          echo "a: {$a} / b: {$b}<br />";            $b = 30;         echo "a: {$a} / b: {$b}<br />"; 

output:

a: 20 / b: 20 a: 30 / b: 30

$a , $b referencing same address. first creating reference:

$b =& ref_return(); 

now $a , $b identically. when next assign $b = 30 affects $a well.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -