Forum Moderators: coopster

How to create IF sentence using days?

         

toplisek

10:20 am on Jan 20, 2026 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have a loop and within a loop there are quoted just two options:
$variable = $index === 0 ? 'Today' : 'Tomorrow';
As I have 10 days forecast, how to modify a line within loop to 8 or 10 days?
Today
Tomorrow
Thursday
Friday
Saturday
etc.

No5needinput

3:06 pm on Jan 20, 2026 (gmt 0)

10+ Year Member Top Contributors Of The Month



ChatGPT suggestion...

$dayLabels = ['Today', 'Tomorrow'];

for ($index = 0; $index < 10; $index++) {
if ($index >= 2) {
$dayLabels[$index] = date('l', strtotime("+$index days"));
}

$variable = $dayLabels[$index];
}


Output example:

Today
Tomorrow
Thursday
Friday
Saturday
Sunday
Monday
Tuesday
Wednesday
Thursday

------------------

Index 0 &#8594; Today
Index 1 &#8594; Tomorrow
Index 2+ &#8594; Calculated weekday name
Automatically scales to any number of days

toplisek

11:56 am on Jan 21, 2026 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



So, this should work:
$dayLabels = $index === 0 ? 'Today' : 'Tomorrow';
for ($index = 0; $index < 10; $index++) {
if ($index >= 2) {$dayLabels[$index] = date('l', strtotime("+$index days"));}
$label = $dayLabels[$index];
}
echo "
<div class='" "'>$label</div>
";