这是我的PHP代码,它生成一个月份名称+年份的选择框.我有2个时间戳,我在循环中使用,开始时间戳和结束时间戳.
现在的问题是,例如,如果我的开始时间戳代表01.07.2011,并且在循环中我只添加了30天的时间戳,那么我选择框7月将显示两次.如果我加上31天,那么可能会是一个月.
是否有任何可用的功能可以为每次迭代添加一个月?
<select name="checkinMonth" class="selectform" id="checkinMonth" >
<?php
for($month = $checkin_timestamp; $month <= $checkout_timestamp; $month += 30*60*60*24) {
$checkin_month = getdate($month);
$option_text = strftime("%B %Y",$month);
$option_value = strftime("%Y%m", $month);
$selected = ($checkin_selected == $option_value ? "selected='selected'" : "");
echo "<option value='{$option_value}' {$selected}>{$option_text}</option>";
}
?>
</select>
Run Code Online (Sandbox Code Playgroud)
Dal*_*ley 27
你在寻找类似的东西:
strtotime("+1 month", $myTimestamp);
Run Code Online (Sandbox Code Playgroud)