How to unset multiple variables? [duplicate]

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

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


Solution 1:

try this

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

Solution 2:

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

See Example

http://codepad.org/mZOc81J5

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

Solution 3:

use like this

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

You have to use for loop for this.

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

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