PHP 删除“引用"从一个变量. [英] PHP remove "reference" from a variable.

查看:29
本文介绍了PHP 删除“引用"从一个变量.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码.我想更改 $b 以再次使用它的值.如果我这样做,它也会改变 $a .之前将值分配为 $a 的引用后,如何再次为 $b 分配值?

I have the code below. I want to change $b to use it again with values. If I do so it changes $a as well. How can I assign a value to $b again after previously assigning it as a reference to $a?

$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 new life.

这篇关于PHP 删除“引用"从一个变量.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆