Jump to content

Looping the days of the week


bruckerrlb

Recommended Posts

I'm trying to create a loop, starting from today, until let's say 30 days down the road. The code I have now looks like

<?php
		$today = date("D M d");


			//$theday = date(
			for ($i=$today; $i<=30; $i++)
		  {
			  
		  $date = $today++;

		  ?>
              <option value="<?php echo $date; ?>"><?php echo $date;?></option>
              <?php
		  echo $date;
		  }
			?>

This just seems to be looping the number part (d) and not the M or the D, can someone show me how to do this or point me in the right direction?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/200579-looping-the-days-of-the-week/
Share on other sites

$i=1;
while ($i<31) {
  if($i==1) {
    echo date('Y-m-d', strtotime("+1 days"))  . "<br>";
  }else{
   echo date('Y-m-d', strtotime("+$i days")) . "<br>";
  }
$i++;
}

I don't see the reason for having both echo lines in the above code, since essentially it will do the same with just

 

$i=1;
while ($i<31) {
    echo date('Y-m-d', strtotime("+$i days")) . "<br>";
    $i++;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.