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

我怕爱的太早我们不能终老 提交于 2019-11-27 07:36:52

问题


I have a pretty high traffic social network site,
I would like to get into the habit of unsetting large array and mysql object and even some string variables.

So is it possible to unset more then 1 item in PHP

example:

<?PHP

unset($var1);

// could be like

unset($var1,$var2,$var3);

?>

回答1:


Yes.

Your example will work just as you imagine. The method signature for unset() is as follows:

void unset ( mixed $var [, mixed $var [, mixed $... ]] )



回答2:


The PHP manual can be very handy. You can search for any built-in function and get a pretty detailed description of what that function does, etc. And the answer is yes, you can supply unset with as many variables as you want.




回答3:


Yes, see the PHP manual, Example 1:

http://us2.php.net/manual/en/function.unset.php




回答4:


Also you can extend any PHP function, look at example

function multiply_foo()
{
    foreach(func_get_args() AS $arg)
        foo($arg);
}

multiply_foo($arg1, $arg2, $arg3);

via PHP: func_get_args



来源:https://stackoverflow.com/questions/1275766/can-you-unset-many-variables-at-once-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!