Page 1 of 1
argh my head hurts. a really easy thing to do, but how?
Posted: Sat Jan 24, 2004 5:44 am
by lizlazloz
ok, um, say i have this:
Code: Select all
$1="something";
$2="somethingelse1";
$3="somethingelse2";
then $_GET[number] comes along.
what i want is so that, if $_GET[number] = 1 , $result="something"
and if it is 2, it is somethingelse1, etc etc.
ho on earth would i do that? my brain is kinda sleepy today...
Posted: Sat Jan 24, 2004 5:59 am
by McGruff
Code: Select all
<?php
$result = 'something' . $_GET['number'];
?>
Posted: Sat Jan 24, 2004 6:12 am
by lizlazloz
oops, 'something' is only an example. really with would be a name. so they dont just have a number after them...
Posted: Sat Jan 24, 2004 6:16 am
by malcolmboston
could it be done with all the values being unique?
Posted: Sat Jan 24, 2004 6:20 am
by markl999
I know it was just an example, but $1, $2 etc are illegal vars names

But if you have
$foo1 = 'something';
$foo2 = 'blah';
$foo3 = 'eek'; etc..etc..
then $result = ${'foo'.$_GET['number']}; should do what you want.
Posted: Sat Jan 24, 2004 6:21 am
by lizlazloz
huh huh huh? i dont know what you mean.
anyway, i made the problem a bit simpler i think....
$r1=$row1[r1];
$r2=$row1[r2];
$r3=$row1[r3];
$r4=$row1[r4];
(from a db table)
$_GET[number] has either the value r1,r2,r3 or r4.
so how can i make $result on of them 4 variables, depending on what $_GET[number] is?
Posted: Sat Jan 24, 2004 6:44 am
by markl999
$result = ${$_GET['number']};
or just..
$result = $row1[$_GET['number']]; and skip the temp var assignments ($r1 = , $r2= etc..)