PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
lizlazloz
Forum Commoner
Posts: 64 Joined: Mon Dec 29, 2003 7:29 am
Post
by lizlazloz » Sat Jan 24, 2004 5:44 am
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...
McGruff
DevNet Master
Posts: 2893 Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland
Post
by McGruff » Sat Jan 24, 2004 5:59 am
Code: Select all
<?php
$result = 'something' . $_GET['number'];
?>
Last edited by
McGruff on Tue Aug 09, 2005 9:56 pm, edited 1 time in total.
lizlazloz
Forum Commoner
Posts: 64 Joined: Mon Dec 29, 2003 7:29 am
Post
by lizlazloz » Sat Jan 24, 2004 6:12 am
oops, 'something' is only an example. really with would be a name. so they dont just have a number after them...
malcolmboston
DevNet Resident
Posts: 1826 Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK
Post
by malcolmboston » Sat Jan 24, 2004 6:16 am
could it be done with all the values being unique?
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sat Jan 24, 2004 6:20 am
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.
lizlazloz
Forum Commoner
Posts: 64 Joined: Mon Dec 29, 2003 7:29 am
Post
by lizlazloz » Sat Jan 24, 2004 6:21 am
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?
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sat Jan 24, 2004 6:44 am
$result = ${$_GET['number']};
or just..
$result = $row1[$_GET['number']]; and skip the temp var assignments ($r1 = , $r2= etc..)