Jump to content

Probably easy?


electrix

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...


Link to comment
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.
Link to comment
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]
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.