开发者

Reverse loop for date display

开发者 https://www.devze.com 2022-12-26 17:23 出处:网络
I\'ve been trying to figure this out and can\'t seem to get it. Here is the code.. $m= date(\"m\"); $de= date(\"d\");

I've been trying to figure this out and can't seem to get it.

Here is the code..

   $m= date("m");
   $de= date("d");
   $y= date("Y");
   for($i=0; $i<=6; $i++){
       echo "<br>";
       echo date('m/d',mktime(0,0,0,$m,($de+$i),$y));
       echo "<br>";
   }

It displays the following.

04/08

04/07

04/06

04/05

04/04

04/03

04/02

That is exactly what I want, but I want it to flip around so echos it would look like the following.

开发者_开发技巧
04/02

04/03

04/04

04/05

04/06

04/07

04/07

How would I do this?


Well, this one's easier, isn't it:

for($i=-6; $i<=0; $i++){
   printf('<br>%s<br>', date('m/d', strtotime("+$i days")));
}

prints

<br>04/02<br><br>04/03<br><br>04/04<br><br>04/05<br><br>04/06<br><br>04/07<br><br>04/08<br>


How about changing the order:

for($i=6; $i>=0; $i--) 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号