I use a loop and 8 variables with almost the same name.
$date1,$date2,$date3,etc..
Now I want to do in the loop echo $date$i Any idea how to achieve this ?
The PHP loop :
$i = 1;
while ($i < 8 ) {
echo $date$i;
$i++;
}
Usually you'll use an array for that:
$data = array('x', 'y', 'z', 'a', 'b', 'c', '1' , '2');
for($i = 0; $i < 8; $i++) {
echo $data[$i];
}
However if you for whatever reason need 8 variables (I can't see a reason), you need to do it like this:
for($i = 0; $i < 8; $i++) {
echo ${"data$i"};
}
$date.$i