JasonDavis
JasonDavis

Reputation: 48933

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

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);

?>

Upvotes: 18

Views: 7717

Answers (4)

jason
jason

Reputation: 8918

Yes.

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

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

Upvotes: 37

Mark Pegasov
Mark Pegasov

Reputation: 5289

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

Upvotes: 0

Mark Rushakoff
Mark Rushakoff

Reputation: 258148

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.

Upvotes: 13

Jefe
Jefe

Reputation: 598

Yes, see the PHP manual, Example 1:

https://www.php.net/manual/en/function.unset.php

Upvotes: 3

Related Questions