php 如何取消设置多个变量?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12633877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:56:31  来源:igfitidea点击:

How to unset multiple variables?

phpvariablesunset

提问by Yousuf Memon

Possible Duplicate:
Can you unset() many variables at once in PHP?

可能的重复:
你能在 PHP 中一次 unset() 多个变量吗?

I have 3 variables var1var2var3. Is there's a way of un-setting them without repeated use of unset()function ?

我有 3 个变量var1var2var3。有没有办法在不重复使用unset()功能的情况下取消设置它们?

回答by webCoder

try this

尝试这个

unset($foo1, $foo2, $foo3);

回答by Ashwini Agarwal

Don't use foreachloop for this. Since it works with a copy of array.

不要foreach为此使用循环。因为它适用于数组的副本。

See Example

见示例

http://codepad.org/mZOc81J5

http://codepad.org/mZOc81J5

IF you want to do this using loop then use forloop.

如果您想使用循环执行此操作,请使用for循环。

回答by Yogesh Suthar

use like this

像这样使用

for($i=0 ; $i<count($array) ; $i++)
{
    unset($array[$i]);
}

You have to use forloop for this.

您必须为此使用for循环。

you can use foreachloop but it will not unset all variable one variable still remains.

您可以使用foreach循环,但它不会取消设置所有变量,一个变量仍然存在。

foreach($array as $arr)
{
    unset($array[$arr]);
}