Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

unset

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

?>
like image 533
JasonDavis Avatar asked Aug 14 '09 02:08

JasonDavis


People also ask

How do you unset multiple variables in PHP?

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 is unset () in PHP?

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.

What's better at freeing memory with PHP unset () or $var Null?

You might get memory freed / shrunk faster, but it may steal CPU cycles from the code that truly needs them sooner, resulting in a longer overall execution time. It seems that $a = null is a bit faster than its unset() counterpart: updating a symbol table entry appears to be faster than removing it.

Which function is used to unset variables in PHP?

The unset() function is an inbuilt function in PHP which is used to unset a specified variable.


1 Answers

Yes.

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

void unset ( mixed $var [, mixed $var [, mixed $... ]] )
like image 195
jason Avatar answered Oct 11 '22 07:10

jason