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);
?>
You have to use for loop for this. you can use foreach loop but it will not unset all variable one variable still remains.
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.
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.
The unset() function is an inbuilt function in PHP which is used to unset a specified variable.
Yes.
Your example will work just as you imagine.
The method signature for unset()
is as follows:
void unset ( mixed $var [, mixed $var [, mixed $... ]] )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With