On 12 December 2003 06:07, motorpsychkill wrote:
> Thanks Tom, that worked! I knew that $$level had something
> to do with it,
> just wasn't sure what exactly. Thanks again.
>
> -m
>
> -----Original Message-----
> From: Tom Rogers [mailto:[EMAIL PROTECTED]
> Sent: Thursday, December 11, 2003 9:34 PM
> To: motorpsychkill
> Subject: Re: [PHP] passing arrays?
>
> Always use isset() to check if something exists before trying
> to use it if
> originates externally to the running script.
>
> you probabley need something like this
>
> $level_0 = array('NONE');
> $level_1 = array("PN", "GALUP", "VP", "PUBUP", "STATS", "MCI",
> "CONLIST","CP", "OAFS", "LO");
> $level_2 = array("PN", "GALUP", "VP", "PUBUP", "MCI", "CONLIST",
> "CP", "OAFS", "LO");
>
> if(isset($_SESSION['user']['level'])){
> $level = 'level_'.$_SESSION['user']['level']; }else{
> $level = 'level_0'; //catchall value
> }
> foreach($$level as $value){
> echo $value.'<br>';
> }
Actually, I'd like to suggest that a variable variable is the wrong tool for
this, and an array should be used instead -- something like:
$level = array(1 => array("PN", "GALUP", "VP", "PUBUP",
"STATS", "MCI", "CONLIST","CP",
"OAFS", "LO"),
2 => array("PN", "GALUP", "VP", "PUBUP",
"MCI", "CONLIST", "CP", "OAFS",
"LO")
);
if (isset($_SESSION['user']['level'])
&& isset($level[$_SESSION['user']['level']])):
foreach ($level[$_SESSION['user']['level']] as $value):
echo $value.'<br>';
endforeach;
else:
// invalid level
endif;
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php