Re: dynamic variabels
| From: | KOYAMA Tetsuji | Date: | Thu, 02 Nov 2000 14:08:54 +0000 |
| Subject: | Re: dynamic variabels | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-23392@lists.php.net to get a copy of this message | ||
Hi,
At Thu, 2 Nov 2000 13:50:52 +0100 (CET),
Tijmen Hennink wrote:
> Doen anybody know how to solve the following problem.
> I'm trying to prevent to use a large switch statement but unfortunately
> this code doesn't work yet.
> function test($varname) {
> $var = "\$this->" . $varname;
> $selectedarray =$this->layer->getTrefwoordenArray($var);
> }
'$this->$varname' is correct. In this case:
function test($varname) {
$var = $this->$varname;
$selectedarray =$this->layer->getTrefwoordenArray($var);
}
> The normal approach would be
> switch($var) {
> case 1:
> $selectedarray=$this->layer->getTrefwoordenArray($this->1);
> break;
> case 2:
> $selectedarray=$this->layer->getTrefwoordenArray($this->2);
> break;
> // and so on for about 20 variabeles.
> }
But, is '1', '2' correct variable name? I seem the variable name must
start with alphabet character, not number.
--
koyama@hoge.org
koyama@beatraft.com
KOYAMA Tetsuji BeatCraft, Inc., Tokyo, Japan.