PHP中“&”符号的含义是什么?

这个问题在这里已经有了答案:

  • 参考 - 这个符号在PHP中的含义是什么? 18个答案

  • 这将强制变量通过引用传递。 通常,为简单类型创建一个硬拷贝。 这对于大型字符串(性能增益)来说可能非常方便,或者如果您想在不使用return语句的情况下操作变量,例如:

    $a = 1;
    
    function inc(&$input)
    {
       $input++;
    }
    
    inc($a);
    
    echo $a; // 2
    

    对象将自动通过引用传递。

    如果你想处理复制到一个函数,使用

    clone $object;
    

    然后,原始对象不会改变,例如:

    $a = new Obj;
    $a->prop = 1;
    $b = clone $a;
    $b->prop = 2; // $a->prop remains at 1
    

    变量前的&符号表示对原始的引用,而不是副本或值。

    看到这里:http://www.phpreferencebook.com/samples/php-pass-by-reference/


    这通过引用而不是值来传递。

    看到:

    http://php.net/manual/en/language.references.php
    http://php.net/manual/en/language.references.pass.php

    链接地址: http://www.djcxy.com/p/1697.html

    上一篇: What does the "&" sign mean in PHP?

    下一篇: What does "&" mean in this case?