PHP变量的指针,在变量前加&号
以下是手册中关于PHP变量的指针的例子,理解一下.
注意其中几行加粗的,变量的变化.
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 = $a\n"; //$a = eh
echo "\$b = $b\n"; //$b = eh
echo "\$c = $c\n"; //$c = eh
echo "\$d = $d\n"; //$d = meh
$c = & $d ;// $c == 'meh'
echo "\n";
echo "\$a = $a\n"; //$a = eh
echo "\$b = $b\n"; //$b = eh
echo "\$c = $c\n"; //$c = meh
echo "\$d = $d\n"; //$d = meh
?>
<!-- Value of c changed -->
<?
$a = 'eh';
$b = & $a;// $b == 'eh'
$c = & $b;// $c == 'eh'
$d = 'meh';
echo "\$a = $a\n"; //$a = eh
echo "\$b = $b\n"; //$b = eh
echo "\$c = $c\n"; //$c = eh
echo "\$d = $d\n"; //$d = meh
$c = 'meh' ;// $c == 'meh'. And also, $a = $b == 'meh'
echo "\n";
echo "\$a = $a\n"; //$a = meh
echo "\$b = $b\n"; //$b = meh
echo "\$c = $c\n"; //$c = meh
echo "\$d = $d\n"; //$d = meh
?>
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
Incoming search terms:
- php 指针
- PHP指针
- php 变量前加&
- php 指针变量
- php 变量地址
- php指针变量
- php变量指针
- 指针变量前加&
- php 变量前面加&
- php & 变量的指标(加在变量前)
- php指针自加
- php 变量的指标
Tags: PHP
受益了。clothingshelf.com