Jump to content


Photo

Probably easy?


  • Please log in to reply
5 replies to this topic

#1 electrix

electrix
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 20 September 2006 - 09:43 AM

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




#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 20 September 2006 - 09:49 AM

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:
$num = '1235';

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

echo $_1235;

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

#3 electrix

electrix
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 20 September 2006 - 09:52 AM

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:

$num = '1235';

$_{$numb} = $num;

echo $_1235;

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


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

$_{$nummer}=$nummer;
echo '"'.$_00.'"';


#4 electrix

electrix
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 20 September 2006 - 09:55 AM

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:

$num = '1235';

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

echo $_1235;

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


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

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 20 September 2006 - 10:01 AM

Yeah I editted my post. I made a mistake with the code. Try the new code:
$num = '1235';

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

echo $_1235;


#6 electrix

electrix
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 20 September 2006 - 12:02 PM

Yeah I editted my post. I made a mistake with the code. Try the new code:

$num = '1235';

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

echo $_1235;


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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users