RE: [PHP] Re: passing arrays?
| From: | motorpsychkill | Date: | Fri, 12 Dec 2003 19:20:38 +0000 |
| Subject: | RE: [PHP] Re: passing arrays? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-172595@lists.php.net to get a copy of this message | ||
Thank you Al for the pointers. This has been very helpful!
-m
> -----Original Message-----
> From: Al [mailto:php.newsgroups@allysays.com]
> Sent: Thursday, December 11, 2003 10:28 PM
> To: php-general@lists.php.net
> Subject: [PHP] Re: passing arrays?
>
>
> > $level = '$level_' . $_SESSION['user']['level'];
> > //Where $_SESSION['user']['level'] can equal "1" or
> > "2"
> >
> > $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");
>
> I can see two problems with your code:
>
> 1) The syntax for assigning to $level is wrong.
> Rather than:
> $level = '$level_' . $_SESSION['user']['level'];
> your code should read:
> $level = ${'level_' . $_SESSION['user']['level']};
> For more information on this syntax, see:
> http://us2.php.net/manual/en/language.variables.variable.php
>
> 2) You are assigning $level_1 or $level_2 (depending on the value of
> $_SESSION['user']['level']) to $level *before* you have assigned
> $level_1 or
> $level_2 any values. There's no point making $level = $level_1 if $level_1
> hasn't been defined yet.
>
> Working code would be:
>
> $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");
> $level = ${'level_' . $_SESSION['user']['level']};
>
> Hope it helps,
>
> Al
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>