I have a variable in a variable.

I have done this before but it is not working this time.

I have it in a for loop so my code is:

$abc1 = one;
 $abc2 = two;
 for($i = 0; $i < 2; $i++) {
  echo $$abc$i;  
 }

The out come should be "one two", correct?

The concept is correct? The code is correct? - to the best of my knowledge and references.

Any ideas? Thanks, Regards X.

The best way to do this would probably be an array:

$abc=array("value1","value2");

for($i = 0; $i < 2; $i++) {
echo $abc[$i];
}

Ya true xan but due to many reasons I cant (mysql - retrieving rows then calculations).

:(

I have a variable in a variable.

I have done this before but it is not working this time.

I have it in a for loop so my code is:

$abc1 = one;
 $abc2 = two;
 for($i = 0; $i < 2; $i++) {
  echo $$abc$i;  
 }

The out come should be "one two", correct?

The concept is correct? The code is correct? - to the best of my knowledge and references.

Any ideas? Thanks, Regards X.

The output will not be one two because $abc1 is one and not $abc0. Try this.

<?php 
$abc1 = "one";
 $abc2 = "two";
 for($i = 1; $i <= 2; $i++) {
  echo ${abc.$i}; //value of $i will be concatenated to string abc and then it will consider the whole as a variable  
 }
 ?>

Been really busy with this week with work, wont be able to test this until the weekend or next weekend. But if your 120% this will work ill mark this solved and give you credit and test it later.

Heh! I tested it before posting it here and I am 200% sure it will work..

Comments
php guru once again :)

done work, it worked for me.

Now off to solve weirdo problems.

Might post them later.

Thanks nav once again :)

This question has already been answered. Start a new discussion instead.