问一下,一个指针,带*号,和不带*咋个用的啊

解决方案 »

  1.   

    以下是手册中关于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
      

  2.   

    *是地址引用...并不是指针...比如:
    $a = 'a';
    $b = &$a;   //$b='a',$a='a'
    $a = 'b';   //$b='b',$a='a'
    如果使用引用的话,$b会随着引用的$a的值而变...而
    $a = 'a';
    $b = $a;   //$b='a',$a='a'
    $a = 'b';  //$b='a',$a='b'
    而没使用地址引用的就不会变...
      

  3.   

    $a = 'a';
    $b = &$a;
    $a = 'b';  //$b='b',$a='b'不好意思,手误...呵呵...