php - What is the difference between “=” and “=&” when assigning variables? -
i trying figure out difference between $a=&$b
, $a=$b
. know &
make variable reference variable. following test gave me same result. can explain difference? thanks.
$a=5; $b=6; $a=&$b; echo $a; //6 $a=5; $b=6; $a=$b; echo $a; //6
first of all: you'll hardly ever need references, avoid confusion of using them if can.
$a=5; //assign value $b=&$a; //make $b reference $a $b=6; //assigning value $b assigns same value $a (as point same location echo $a; //6 $a=5; //assign value $b=$a; //set $b value of $a $b=6; //set $b value leaves $a @ it's original value echo $a; //5
Comments
Post a Comment