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))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题