asmith Posted December 31, 2007 Share Posted December 31, 2007 is that possible that i unset all the variables i have set up in a file ? i'm fetching some rows from mysql table : while (aaa = mysql_fetch_array... ) then for each row i'm setting some variables like : if aaa[name] = "john" { $a= true; $b = "name" } now when the main while loop that is fetching goes to the next row and in the next row aaa[name] wasn't "john" , so $a shouldn't be true . so it skips the if part ... but as $a is set true from the last row, so although it skips the if part, but $a is still true . as i 've set lots of variables , it takes so much time to search for them and fix them , wanted to know is that possible i reset all the variable AFTER each while loop results ? ( if all the variables reset , then variabes in while loop ill destroy too ) thanks Quote Link to comment https://forums.phpfreaks.com/topic/83818-unset-all-variables/ Share on other sites More sharing options...
marcus Posted December 31, 2007 Share Posted December 31, 2007 <?php $text = "bubbles"; echo $text; unset($text); echo $text; ?> Quote Link to comment https://forums.phpfreaks.com/topic/83818-unset-all-variables/#findComment-426495 Share on other sites More sharing options...
rajivgonsalves Posted December 31, 2007 Share Posted December 31, 2007 try foreach ($GLOBALS as $strKey => $arrValue) { if (!is_array($GLOBALS[$strKey])) { unset($GLOBALS[$strKey); } } Quote Link to comment https://forums.phpfreaks.com/topic/83818-unset-all-variables/#findComment-426498 Share on other sites More sharing options...
asmith Posted December 31, 2007 Author Share Posted December 31, 2007 $GLOBALS contain so many variables other than the variables i've set , cause no problem unsetting them too ? Quote Link to comment https://forums.phpfreaks.com/topic/83818-unset-all-variables/#findComment-426506 Share on other sites More sharing options...
rajivgonsalves Posted December 31, 2007 Share Posted December 31, 2007 Yeah, thats the problem , either you unset everything or you have a list of your variables... in an array Quote Link to comment https://forums.phpfreaks.com/topic/83818-unset-all-variables/#findComment-426513 Share on other sites More sharing options...
asmith Posted December 31, 2007 Author Share Posted December 31, 2007 ok i guess i have to go down that road the highway ! Quote Link to comment https://forums.phpfreaks.com/topic/83818-unset-all-variables/#findComment-426514 Share on other sites More sharing options...
asmith Posted December 31, 2007 Author Share Posted December 31, 2007 hey rajiv , dosen't my variables have a specific location in $GLOBALS ??? can't we use that ? Quote Link to comment https://forums.phpfreaks.com/topic/83818-unset-all-variables/#findComment-426520 Share on other sites More sharing options...
rajivgonsalves Posted December 31, 2007 Share Posted December 31, 2007 Yes they have but the location for anything you set will be at the current location I'll check and see if php has a function to distinguish between user variables and system variables. Quote Link to comment https://forums.phpfreaks.com/topic/83818-unset-all-variables/#findComment-426539 Share on other sites More sharing options...
asmith Posted December 31, 2007 Author Share Posted December 31, 2007 thanks rajiv let me know when you are done . Quote Link to comment https://forums.phpfreaks.com/topic/83818-unset-all-variables/#findComment-426553 Share on other sites More sharing options...
Northern Flame Posted December 31, 2007 Share Posted December 31, 2007 yea just put them in an array like this: <?php $x = 0; while($aaa = mysql_fetch_array...){ $array[$x] = $aaa['column_name']; $x++; } // echo your variables.... unset($array); ?> Quote Link to comment https://forums.phpfreaks.com/topic/83818-unset-all-variables/#findComment-426555 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.