dto52236 2014-03-17 11:28
浏览 56
已采纳

从循环内部获取最后一个日期

This is what I've tried so far:

<?php 
          for( $i = 1; $i <= $month_amortization; $i++ ) {
            $nextmonth = date('F d, Y', strtotime('+'.$i.' month'));

            $last = substr($i, -1, 1);
            switch($last)
            {
                case "1":
                $os = 'st';
                break;

                case "2":
                $os = 'nd';
                break;

                case "3":
                $os = 'rd';
                break;

                default:
                $os = 'th';
            }

          ?>
          <tr>
            <td><?php echo $i; ?></td>
            <td><?php echo $nextmonth; ?></td>
            <td><?php echo $i .$os . ' Monthly Amortization'; ?></td>
            <td><?php echo 'PHP '. number_format($monthly_amortization, 2); ?></td>
          </tr>
          <?php 
          }
          ?>

This displays dates. I want to get the last date from the loop. I tried echoing $nextmonth; but I'm getting only the date today. How can I get the last date from inside the loop? Any ideas? Help is much appreciated. Thanks.

  • 写回答

1条回答

  • dtgj8529 2014-03-17 11:44
    关注

    Try this:

    $last_month = date('F d, Y', strtotime('+'.$month_amortization.' month'));
    for( $i = 1; $i <= $month_amortization; $i++ ) {
        // your code here...
        ?><tr>
            <td><?php echo $i; ?></td>
            <td><?php echo $last_month; ?></td>
            <td><?php echo $i .$os . ' Monthly Amortization'; ?></td>
            <td><?php echo 'PHP '. number_format($monthly_amortization, 2); ?></td>
        </tr><?php 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置