Can you please help me in getting data out of this for loop. It actually should print the names of 3 months, which it does if i dont use the $ period variable in there and use echo instead. But I want to put the value into the $period variable, so I can use it else where in my script. Right now, it print out only one month.
for ($i=1; $i<=3; $i++)
{
$period = '<option value="">';
$period .= date('F, Y', strtotime('+'.$i.' month'));
$period .= '</option>';
}
echo $period;
You’re overwriting the value of $period on each iteration. Try the code below: