Reputation: 69
I have multiple PHP variables in the form
$number1, $number2, $number3 and so on...
I would like to dynamically reference these inside of a loop to retrieve information from them, but am not sure how to reference the static variable dynamically. Ex:
for($i = 1; $i <= 10; $i++) {
//The first number to be printed should be the value from
//$number1 not $number concatenated to $i
//here are some of the strings I tried:
echo "$number$i";
echo "{$number}$i";
echo "{$number}{$i}";
}
Upvotes: 2
Views: 3068
Reputation: 16719
This should do it:
echo ${"number{$i}"};
But why not use arrays instead? Having $number[$i]
is much more readable...
Upvotes: 6