note 126294 deleted from language.references.whatdo by cmb
| From: | cmb@php.net | Date: | Sat, 31 Jul 2021 10:36:51 +0000 |
| Subject: | note 126294 deleted from language.references.whatdo by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-216700@lists.php.net to get a copy of this message | ||
Note Submitter: dexant9t at gmail dot com
----
It matters if you are playing with a reference or with a value
Here we are working with values so working on a reference updates original variable too;
$a = 1;
$c = 22;
$b = & $a;
echo "$a, $b"; //Output: 1, 1
$b++;
echo "$a, $b";//Output: 2, 2 both values are updated
$b = 10;
echo "$a, $b";//Output: 10, 10 both values are updated
$b =$c; //This assigns value 2 to $b which also updates $a
echo "$a, $b";//Output: 22, 22
But, if instead of $b=$c you do
$b = &$c; //Only value of $b is updated, $a still points to 10, $b serves now reference to
variable $c
echo "$a, $b"//Output: 10, 22