Variable with variable value

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

Post Reply
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Variable with variable value

Post by tecktalkcm0391 »

Is there a way to make a variable be like this:

say $x = 3
so I want the variable to be $3_sc
and if $x=2
it would make the variable $2_sc

I am just wondering thanks
Thanks
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Yup, but a variable can't start with a number.

Code: Select all

$bob_whatever = "hello!";
$x = "bob";
$x .= "_whatever";
echo $$x;
//outputs hello!
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

Cool. Iknow about the number thing but didn't think about it in my example.
Post Reply