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 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名