Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 365
Yousuf Memon Avatar asked Sep 28 '12 05:09

Yousuf Memon


People also ask

How do you unset multiple variables in PHP?

IF you want to do this using loop then use for loop. Show activity on this post. You have to use for loop for this. you can use foreach loop but it will not unset all variable one variable still remains.

What does unset() do?

unset() destroys the specified variables. The behavior of unset() inside of a function can vary depending on what type of variable you are attempting to destroy. If a globalized variable is unset() inside of a function, only the local variable is destroyed.

How to unset an array in PHP?

Using unset() Function: The unset() function is used to remove element from the array. The unset function is used to destroy any other variable and same way use to delete any element of an array. This unset command takes the array key as input and removed that element from the array.


1 Answers

try this

unset($foo1, $foo2, $foo3); 
like image 181
webCoder Avatar answered Oct 20 '22 09:10

webCoder