[thelist] PHP syntax - output of two variables in a string

Fred Jones fredthejonester at gmail.com
Mon Jun 25 11:17:31 CDT 2007


Bob Meetin wrote:
> Having some trouble with a loop, seems simple enough, but... The loop is 
> incrementing fine, it's my misunderstanding of how to escape or set the 
> variables correctly.
> 
> $abc = "abc";
> $abc1 = "apples";
> $abc2 = "pumpkins";
> 
> When:
> $n = 1;
> $output = "$abc$n";
> echo "Output: $output<br>";

Basically you need to use an array, not a set of literals. As in:

$abc = [];
$abc[0] = "abc";
$abc[1] = "apples";
$abc[2] = "pumpkins";

and then

$output = "$abc[$n]";

Fred



More information about the thelist mailing list