[SOLVED] Help with While and variable


I try to make a simple while loop like this :

<?php $i=1; while ($i <= $number) { ?> <?php echo $test ?> <?php $i++; } ?>[/php]

In another php file (loaded with required_once)

I have this:

$number = "8"; $test1 = "hello1"; $test2 = "hello2"; $test3 = "hello3";

What I want is that in the while loop, the $test variable would be replace by $test1, $test2, $test3, ect…

I’ve make several trest but all I am able to do is display “test1” instead of “hello1” using $test.=$i

Can someone help me please?

Thanks ![/code]

use an array

$test[] = "hello1"; $test[] = "hello2"; $test[] = "hello3";

and foreach
foreach($test as $t)

echo $t;
echo ‘’;


Thanks it’s work great.

But, suppose that I have more than one variable to output in my foreach loop :slight_smile:

use foreach($test as $key => $t)

and output the second array with $arrayname[$key]

of cause the keys in both arrays have to mach.

Work pretty well :)

Thank a lot !

Sponsor our Newsletter | Privacy Policy | Terms of Service