How do you empty an array variable?

Hi all,

How do you empty an array variable? Is is a simple as declaring the array as follows:

//Create the array
$my_array = array(
“m” => “m”,
“y” => “0”,
“e” => $end
);
$my_array = array(
“m” => “m”,
“y” => “0”,
“e” => $end
);

//What goes next to make $my_array equal to “”, is it?
$my_array=“”;

Try
unset($myarray)
or
$myarray = array();

unset($my_array);

but why on earth would you want to do that? :slight_smile:

My reasoning is that I read a full text file into an array and then extract various elements of it into certain variables. Once everything is extracted, the PHP script has many other things to do. However, there is no point in using up CPU memory during this latter phase, hence I want to empty the variable.

Does this make sense or is it a waste of time?

Willie

PHP is smart, it’ll empty it on its own. Are you coming from ASP by any chance?

Originally posted by Snoozy
PHP is smart, it’ll empty it on its own. Are you coming from ASP by any chance?

well, yeah, it’ll empty it after the script exits, if that’s what you mean. but it won’t empty it during the script, b/c you might use it still. :slight_smile: and he wants to save memory during the rest of the script. that’s probably a good idea if it was a large array.