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. ??? Quote 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(); Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.