+ 3

Why '&' is used with $a.

$a=5 $b=&$a $b=10 //Then what is the value of $a,and why??

17th May 2019, 5:34 PM
Paresh Kalsotra
Paresh Kalsotra - avatar
3 Réponses
+ 5
& is a reference operator. That means if variable b is referencing var a, so the value of b will change the value of a. If b = 10, then a will also initialize with 10. Try in PHP compiler.
17th May 2019, 6:11 PM
Sachin Artani
Sachin Artani - avatar
+ 3
Here$a=10 but why? please explain
17th May 2019, 5:36 PM
Paresh Kalsotra
Paresh Kalsotra - avatar
+ 3
The & is used to obtain address of a variable, in this case address of variable <$a>. When we assign address of variable <$a> into variable <$b> we are telling variable <$b> to refer to and use the same address that is used by variable <$a>. This is why changes to variable <$b> will reflect on variable <$a>, voce versa. Hth, cmiiw
17th May 2019, 6:13 PM
Ipang