<?php
$b=1; $d=2;
$a =& $b;
$c =& $d;
$b =& $c;
?>
It's also important to treat =& as its own operator, though you can stick spaces in the middle. The & does not bind to the variable, as shown by
<?php
$a = (&$b); ?>
In response to the example by mdiricks.
Extending the example given by mdiricks, the following code provides an explains the concept of re-referencing that is involved in making a call to function foo with the prototype foo(& var):
<!-- C re-referenced -->
<?
$a = 'eh';
$b = & $a;// $b == 'eh'
$c = & $b;// $c == 'eh'
$d = 'meh';
echo "$a = $an";
echo "$b = $bn";
echo "$c = $cn";
echo "$d = $dn";
$c = & $d ;// $c == 'meh'
echo "n";
echo "$a = $an";
echo "$b = $bn";
echo "$c = $cn";
echo "$d = $dn";
?>
<!-- Value of c changed -->
<?
$a = 'eh';
$b = & $a;// $b == 'eh'
$c = & $b;// $c == 'eh'
$d = 'meh';
echo "$a = $an";
echo "$b = $bn";
echo "$c = $cn";
echo "$d = $dn";
$c = 'meh' ;// $c == 'meh'. And also, $a = $b == 'meh'
echo "n";
echo "$a = $an";
echo "$b = $bn";
echo "$c = $cn";
echo "$d = $dn";
?>
This results in the following o/p:
<!-- C re-referenced -->
$a = eh
$b = eh
$c = eh
$d = meh
$a = eh
$b = eh
$c = meh
$d = meh
<!-- Value of c changed -->
$a = eh
$b = eh
$c = eh
$d = meh
$a = meh
$b = meh
$c = meh
$d = meh
I can see why there is a big debate on this. I'm hoping this will clarify it a little.
In PHP, as far as I can understand, when you assign a variable in the first place,
that variable is a refrence to the value that the variable contains.
<?php
$var = "String"; echo $var;
?>
Anyway, when you create a reference to the variable $var,
it doesn't reference the variable's name, but rather its contents.
For example:
<?php
$var2 = & $var;
echo $var2;
5/8 首页 上一页 3 4 5 6 7 8 下一页 尾页 |