1

假设我有一个这样的例子:

$foo = 'Hello ';
$bar = 1;

$abc =& $foo . $bar;

if (true) {
    ++$bar;

    if (true)
    {
        ++$bar;
    }
}

echo $abc;

我期待$abc返回Hello 3,但它实际上只返回Hello。我真的很困惑。我在 PHP 中的引用有什么问题吗?

4

1 回答 1

2

引用变量就像同一个对象/变量的别名,一次只能引用一个变量。

我不确定如何帮助您解决问题,因为我不知道您要做什么,但是..

$foo = 'Hello ';
$bar = 1;

$abc =& $bar;

++$bar;
++$bar;

echo $foo . $abc;

http://www.php.net/manual/en/language.references.whatdo.php

于 2013-11-11T22:01:03.540 回答