Loop through variables with common name

php

Solution

Try `${"hello" . $counter}`

$a = "hell";
$b = "o";
$hello = "world";
echo ${$a . $b};

// output: world

Problem

At first glance I think you can get what I'm trying to do. I want to loop though variables with the same name but with a numerical prefix. I also had some confusion about the kind of loop I should use, not sure if a "for" loop would work. The only thing is I can't wrap my head around how php could interpret "on the fly" or fabricated variable. Ran into some trouble with outputting a string with a dollar sign as well. Thanks in advance! ``` $hello1 = "hello1"; $hello2 = "hello2"; $hello3 = "hello3"; $hello4 = "hello4"; $hello5 = "hello5"; $hello6 = "hello6"; $hello7 = "hello7"; $hello8 = "hello8"; $hello9 = "hello9"; $hello10 = "hello10"; for ( $counter = 1; $counter <= 10; $counter += 1) { echo $hello . $counter . "<br>"; } ```

Original source