What does the "&" sign mean in PHP?

This question already has an answer here:

  • Reference — What does this symbol mean in PHP? 18 answers

  • This will force the variable to be passed by reference. Normally, a hard copy would be created for simple types. This can come handy for large strings (performance gain) or if you want to manipulate the variable without using the return statement, eg:

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

    Objects will be passed by reference automatically.

    If you like to handle a copy over to a function, use

    clone $object;
    

    Then, the original object is not altered, eg:

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

    The ampersand preceding a variable represents a reference to the original, instead of a copy or just the value.

    See here: http://www.phpreferencebook.com/samples/php-pass-by-reference/


    This passes something by reference instead of value.

    See:

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

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

    上一篇: 这个签名在PHP中意味着什么(&)?

    下一篇: PHP中“&”符号的含义是什么?