newtoall Posted May 22, 2007 Share Posted May 22, 2007 I have an array being created a number of times with in a loop, before it is created I want to check if it empty and if it isn't then clear it down. How do I do this?? Any help you can provide will help preserve my sanity. Rich. ??? Link to comment https://forums.phpfreaks.com/topic/52489-how-to-empty-an-array/ Share on other sites More sharing options...
taith Posted May 22, 2007 Share Posted May 22, 2007 if(!empty($array)) $array=array(); Link to comment https://forums.phpfreaks.com/topic/52489-how-to-empty-an-array/#findComment-259010 Share on other sites More sharing options...
kenrbnsn Posted May 22, 2007 Share Posted May 22, 2007 You can use the [http://www.php.net/unset]unset()[/url] function and then recreated it. Just recreating it works find too. <?php $tst = array('test','test1','test2','test3'); echo 'Before: <pre>' . print_r($tst,true) . '</pre>'; unset($tst); $tst = array(); echo 'After: <pre>' . print_r($tst,true) . '</pre>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/52489-how-to-empty-an-array/#findComment-259011 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.