alin19 Posted February 12, 2008 Share Posted February 12, 2008 $zile =null; i need this array to have no elements how can i empty an array? $query="SELECT * FROM `$operator`"; if ($r=mysql_query($query)) { while ($row = mysql_fetch_array($r)) { $zile[]=$row['zi']; $cupoane[]=$row['nr.cupoane']; $lunabd[]=$row['luna']; echo " "; } } Quote Link to comment https://forums.phpfreaks.com/topic/90643-empty-an-array/ Share on other sites More sharing options...
Psycho Posted February 12, 2008 Share Posted February 12, 2008 unset($zile); Quote Link to comment https://forums.phpfreaks.com/topic/90643-empty-an-array/#findComment-464666 Share on other sites More sharing options...
Barand Posted February 12, 2008 Share Posted February 12, 2008 $zile = array(); The declaration should be there before you reference it Quote Link to comment https://forums.phpfreaks.com/topic/90643-empty-an-array/#findComment-464668 Share on other sites More sharing options...
alin19 Posted February 12, 2008 Author Share Posted February 12, 2008 but it works this way also; would that help? Quote Link to comment https://forums.phpfreaks.com/topic/90643-empty-an-array/#findComment-464670 Share on other sites More sharing options...
Barand Posted February 12, 2008 Share Posted February 12, 2008 It's good programming practice always to initialise variables. Also, should you move your code as it is to a server with error_reporting (E_ALL) set as default then it's going to generate a warning. Quote Link to comment https://forums.phpfreaks.com/topic/90643-empty-an-array/#findComment-465162 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.