Re: passing arrays?

From: Date: Fri, 12 Dec 2003 06:28:21 +0000
Subject: Re: passing arrays?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-172550@lists.php.net to get a copy of this message
> $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

« previous php.general (#172550) next »