我有下面的代码。我想更改 $b 以再次使用它的值。如果我这样做,它也会改变 $a 。在之前将其作为对 $a 的引用赋值后,如何再次将值赋给 $b?
$a = 1;
$b = &$a;
// later
$b = null;
最佳答案
查看内联解释
$a = 1; // Initialize it
$b = &$a; // Now $b and $a becomes same variable with
// just 2 different names
unset($b); // $b name is gone, vanished from the context.
// But $a is still available
$b = 2; // Now $b is just like a new variable with a new value.
// Starting a new life.
关于PHP 从变量中删除 "reference"。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9031076/