try (meaning, I think that $vars as $keys will put the value into $key, not the key itself):
foreach ($vars as $key=>$value) // clear all previous sessions { if(isset($_SESSION['$key'])) { unset($_SESSION['$key']); } }
Ryan A wrote:
Hi, I am just screwing around and getting used to arrays with a "foreach" thanks to Michael,Jan and Evan from this list and have run into problems.
My requirment is pretty simple (code is below too) 1)unset all the sessions that might have been set with reference to the hardcoded array ($vars) 2)if any checkboxes have been set from the previous form then set that session needless to say, its not working, am too new at this to know where my fault is so any help is greatly appreciated.
I have even added a few comments as to what i was thinking....tell me if i was wrong.
**************Start code************************ <?php $vars = Array('noPlatform','noPrice','noSfee','noSpace'); // this corresponds to the "name=" of each checkbox
foreach ($vars as $key) // clear all previous sessions { if(isset($_SESSION['$key'])) { unset($_SESSION['$key']); } } echo "done1"; //just checking program execution
foreach ( $vars as $vvvv ) // if any checkboxes were checked create a session for them { ${$vvvv} = ( isset($_POST[$vvvv]) ? 1 : 0 );
if($vvvv==1) { $_SESSION[$vvvv]; echo $vvvv; //getting no output from here...I just put it here for testing } } echo "done2"; //just checking program execution ?>
****************End code************************
Thanks in advance, -Ryan
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php