Dynamic Variable Name / Increment Variable Name

Please can someone assist me with dynamic variables within a loop?
In the code below, I have 4 variables and an echo that loops 4 times.

When the loop runs, each variable should echo (in the code I’ve inserted $var* as a place holder).

How is it possible to increment $var* within the echo statement ($var1 should echo, then $var2 and so on)?

Many thanks

$var1 = ‘A’;
$var2 = ‘B’;
$var3 = ‘C’;
$var4 = ‘D’;

for ($i = 1; $i < 5; $i++) {

echo ($var*);

}

Read more here:: Dynamic Variable Name / Increment Variable Name

Leave a Reply

Your email address will not be published. Required fields are marked *