gpt4 book ai didi

PHP 从变量中删除 "reference"。

转载 作者:可可西里 更新时间:2023-10-31 22:07:16 25 4
gpt4 key购买 nike

我有下面的代码。我想更改 $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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com