doudun3040 2013-05-03 17:12
浏览 36
已采纳

使用php for循环如何将substr周四改为两个字母的缩写?

I'm already substr all the days to 1 letter but I would like only Thursday to be two letters, right now my loop skips weekends and functions properly for a two week out period from today's date.

$lastmonday=strtotime("-".(date("N")-1)." days");
$end=strtotime("+14 days", $lastmonday); 
$datestr = "";

for($i = 1; $i < 14; $i++)
    {
    $curr = strtotime("+".$i." days");
    $weekday = date("N", $curr);

    if ($weekday > 5) continue;

    $datestr .= "sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='$i' then 1 else 0 end)
        '" . substr(date('D', $curr), 0, 1).'<br>' . date('n/j', $curr) . "',";
    }

The problem is Monday - Friday are all being substr to 1. Still new to substr and i know it's very useful. Additionally, I'm just not sure how i can stop the loop at Wednesday and substr Thursday to two letters and than back to one letter for Friday.

Would i break the loop and than use the control structure "continue" again, like i'm doing for the $weekday variable?

  • 写回答

1条回答 默认 最新

  • dongya1228 2013-05-03 17:15
    关注

    Just test the day to see how many characters to grab.

    substr(date('D', $curr), 0, ($weekday == 4 ? 2 : 1))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!