Not sure if the Title is the correct title but I'm not sure how to call what I'm trying to accomplish. On the surface it looks fairly simple...
I wrote the following code:
$var1 = "55";
$var2 = "66";
$var3 = "22";
$var4 = "22";
$x = 1;
$result = "null";
while($x < 5) {
$result = "$" . "var" . "$x";
echo $result;
echo " | ";
$x = $x +1;
}
Was hoping to get: 55 | 66 | 22 |22
Instead I'm getting: $var1 | $var2 | $var3 | $var4 |
I tried many things but unable to find a working solution, any help would be much approached.
Thank you
$var1when you mean to evaluate that string to the value of$var1. I guess you don't know what variable names you will handle beforehand. However, usingevalon an unknown input stream is a bad approach. Use arrays and iterate over them as @PeeHaa said.