我试图在基本的PHP forloop. 目前,我已经能够执行多次并静态编写循环外的n-1代码。除非我使用外部循环,n=n否则这个概念将失败。有没有办法获得循环内的最后一次执行?n = 1if-statement
<?php
$total_time_months = 6;
$time_now = date('Y-m-d H:i:s');
for ($x = 1; $x <= $total_time_months-1; $x++) {
$offset = strtotime('+'. $x .' months');
echo $next_date = date('Y-m-d H:i:s', $offset)."<br>"; // this is the n-1 time
}
//do something statically knowing that there is suposed to be one more left
echo date('Y-m-d H:i:s', strtotime('+'. $total_time_months. ' months'))."<br>";
?>
对于这个问题,n = $total_time_months
紫衣仙女
慕码人2483693