Select 与 php 和 strtotime
Select with php and strtotime
我对 php 中的 strotime 功能有疑问...
这是我期望的 html 示例。
<select>
<option value="2018-02-26" selected>Feb 26 - March 4</option>
<option value="2018-02-19">Feb 19 - Feb 25</option>
<option value="2018-02-12">Feb 12 - Feb 18</option>
<option value="2018-02-05">Feb 05 - Feb 11</option>
</select>
这是我的 php 代码。
for ($i = 0; $i < 7; $i++) {
$option_value = '' . date("Y-m-d", strtotime("this monday - $i week")) . '' . " / " . date("Y-m-d", strtotime("this sunday - $i week")).' / '.$i;
$option_render = date("d/m", strtotime("this monday - $i week")) . " / " . date("d/m", strtotime("this sunday - $i week ")) . '';
}
问题是 php 代码没有呈现我想要的...
这是 php 的结果:
<select>
<option value="2018-03-05">05/03 / 04/03</option>
<option value="2018-02-26">26/02 / 25/02</option>
<option value="2018-02-19">19/02 / 18/02</option>
<option value="2018-02-12">12/02 / 11/02</option>
<option value="2018-02-05">05/02 / 04/02</option>
<option value="2018-01-29">29/01 / 28/01</option>
<option value="2018-01-22">22/01 / 21/01</option>
</select>
for ($i = 0; $i < 7; $i++) {
$option_value = date("Y-m-d", strtotime("this monday - $i week"));
$option_render = date("M d", strtotime("this monday - ".($i+1)." week")) . " - " . date("M d", strtotime("this sunday - $i week "));
}
检查一下,测试输出:
2018-03-05 ~ Feb 26 - Mar 04
2018-02-26 ~ Feb 19 - Feb 25
2018-02-19 ~ Feb 12 - Feb 18
2018-02-12 ~ Feb 05 - Feb 11
2018-02-05 ~ Jan 29 - Feb 04
2018-01-29 ~ Jan 22 - Jan 28
2018-01-22 ~ Jan 15 - Jan 21
我对 php 中的 strotime 功能有疑问... 这是我期望的 html 示例。
<select>
<option value="2018-02-26" selected>Feb 26 - March 4</option>
<option value="2018-02-19">Feb 19 - Feb 25</option>
<option value="2018-02-12">Feb 12 - Feb 18</option>
<option value="2018-02-05">Feb 05 - Feb 11</option>
</select>
这是我的 php 代码。
for ($i = 0; $i < 7; $i++) {
$option_value = '' . date("Y-m-d", strtotime("this monday - $i week")) . '' . " / " . date("Y-m-d", strtotime("this sunday - $i week")).' / '.$i;
$option_render = date("d/m", strtotime("this monday - $i week")) . " / " . date("d/m", strtotime("this sunday - $i week ")) . '';
}
问题是 php 代码没有呈现我想要的... 这是 php 的结果:
<select>
<option value="2018-03-05">05/03 / 04/03</option>
<option value="2018-02-26">26/02 / 25/02</option>
<option value="2018-02-19">19/02 / 18/02</option>
<option value="2018-02-12">12/02 / 11/02</option>
<option value="2018-02-05">05/02 / 04/02</option>
<option value="2018-01-29">29/01 / 28/01</option>
<option value="2018-01-22">22/01 / 21/01</option>
</select>
for ($i = 0; $i < 7; $i++) {
$option_value = date("Y-m-d", strtotime("this monday - $i week"));
$option_render = date("M d", strtotime("this monday - ".($i+1)." week")) . " - " . date("M d", strtotime("this sunday - $i week "));
}
检查一下,测试输出:
2018-03-05 ~ Feb 26 - Mar 04
2018-02-26 ~ Feb 19 - Feb 25
2018-02-19 ~ Feb 12 - Feb 18
2018-02-12 ~ Feb 05 - Feb 11
2018-02-05 ~ Jan 29 - Feb 04
2018-01-29 ~ Jan 22 - Jan 28
2018-01-22 ~ Jan 15 - Jan 21