amiawizard amiawizard - 1 year ago 92
PHP Question

Best way to clear a PHP array's values

Which is more efficient for clearing all values in an array? The first one would require me to use that function each time in the loop of the second example.

foreach ($array as $i => $value) {

Or this

foreach($blah_blah as $blah) {
$foo = array();
//do something
$foo = null;

Answer Source

Use unset, if you need the array later on just instantiate it again.

$foo = array();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download