Jump to content

Archived

This topic is now archived and is closed to further replies.

electrix

Probably easy?

Recommended Posts

I've been googl'ing for the last 3 hours now without luck...

example:
--------------------
$number="00";
--------------------

$_$number="$number"
echo $_00;
--------------------
This should display "00" on the screen.
I'm not a newbie with this so don't gimme the "echo $number should work"-speach.
That's not what I want as in $number is actually a variable number taken from a user-inserted database.

Easiest explanation:
I want the name of the variabel ($number=) should be the same as the value (= $var;)

Hope any1 understand what I mean...


Share this post


Link to post
Share on other sites
You mean you wnat to create a variable that has the same name as its value? Ie you ahve variable holds the number 1234 and you want to create a new variable which has the name 1234 and holds the value of 1234

If you do then you'll want to use curly braces:
[code=php:0]$num = '1235';

${'_' . $num} = $num;

echo $_1235;[/code]

Note if you want to the variabled to be $1234, then you cannot do that as variable names must not start with a number.

Share this post


Link to post
Share on other sites
[quote author=wildteen88 link=topic=108756.msg437795#msg437795 date=1158745756]
You mean you wnat to create a variable that has the same name as its value? Ie you ahve variable holds the number 1234 and you want to create a new variable which has the name 1234 and holds the value of 1234

If you do then you'll want to use curly braces:
[code=php:0]$num = '1235';

$_{$numb} = $num;

echo $_1235;[/code]

Note if you want to the variabled to be $1234, then you cannot do that as variable names must not start with a number.
[/quote]

That I knew of (not start with a number I mean.)
Still not working...What am I doing wrong?!
[code]$nummer="00";

$_{$nummer}=$nummer;
echo '"'.$_00.'"'; [/code]

Share this post


Link to post
Share on other sites
[quote author=wildteen88 link=topic=108756.msg437795#msg437795 date=1158745756]
You mean you wnat to create a variable that has the same name as its value? Ie you ahve variable holds the number 1234 and you want to create a new variable which has the name 1234 and holds the value of 1234

If you do then you'll want to use curly braces:
[code=php:0]$num = '1235';

${'_' . $num} = $num;

echo $_1235;[/code]

Note if you want to the variabled to be $1234, then you cannot do that as variable names must not start with a number.
[/quote]

You just edited your post right?  ;) Or else I copied extremely wrong :P

Share this post


Link to post
Share on other sites
Yeah I editted my post. I made a mistake with the code. Try the new code:
[code=php:0]$num = '1235';

${'_' . $num} = $num;

echo $_1235;[/code]

Share this post


Link to post
Share on other sites
[quote author=wildteen88 link=topic=108756.msg437808#msg437808 date=1158746489]
Yeah I editted my post. I made a mistake with the code. Try the new code:
[code=php:0]$num = '1235';

${'_' . $num} = $num;

echo $_1235;[/code]
[/quote]

Just wanted to thank you for your help.
It worked perfect!  :D

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.