Re: Where am i screwing up?

From: Date: Thu, 31 Jul 2003 15:12:44 +0000
Subject: Re: Where am i screwing up?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-157748@lists.php.net to get a copy of this message
* Thus wrote Ryan A (ryan@jumac.com): > > foreach ($vars as $key) // clear all previous sessions > { > if(isset($_SESSION['$key'])) > { > unset($_SESSION['$key']); > } > } > echo "done1"; //just checking program execution No need to loop here, you can use an else statment in the next loop. And the key is inside '' as John pointed out. > > 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 > } > } Couple things: . Try not to use abstract names for vars (ie $vvvv), it makes the code harder to understand what its doing. But since this is a test script I'll let that slide :) . Your ${$vvvv} assingment is never used, read up on how to use variable variables. It isnt and shouldn't be used in this instance. . Try and make things a little simpliler: foreach ($vars as $vvvv) { if ( isset($_POST[$vvvv]) ) { $_SESSION[$vvvv] = 1; // be sure to assign a value. } else { unset($_SESSION[$vvvv]); // no single quotes around the key } } HTH, Curt -- "I used to think I was indecisive, but now I'm not so sure."

« previous php.general (#157748) next »