Home > Backend Development > PHP Tutorial > 用程序输出从礼拜日至星期六,每天变化的只是日期而星期不变

用程序输出从礼拜日至星期六,每天变化的只是日期而星期不变

WBOY
Release: 2016-06-13 12:06:51
Original
945 people have browsed it

用程序输出从星期日至星期六,每天变化的只是日期而星期不变
我弄了一个简单的程序,原先的意思是输出星期日至星期六,但是现在我搞的每天日期和星期都在变化,我想要的结果是这样:
2014-9-28(星期日)
2014-9-29(星期一)
2014-9-30(星期二)
2014-10-1(星期三)
2014-10-2(星期四)
2014-10-3(星期五)
2014-10-4(星期六)
到了2014-10-5(星期日)。。。。。一次类推,只有日期在变,而星期不变,这个怎么实现的呢?这个是我原先的程序,

function getWeek($day){<br />  $days = array('星期日','星期一','星期二','星期三','星期四','星期五','星期六');<br />  $day = explode('-',$day);<br />  return $days[date('w',mktime(0,0,0,$day[1],$day[2],$day[0]))];<br />}<br /><?php<br />for($i = 0;$i < 7;$i++){<br />$day = date('Y-m-d',strtotime(''.($i+1).' day'));<br />echo $day."(".getWeek($day).")";<br />}<br />?><br />
Copy after login

------解决思路----------------------
这个意思?
function getWeek($day){<br />  $days = array('星期日','星期一','星期二','星期三','星期四','星期五','星期六');<br />  return $days[date('w', strtotime($day))];<br />}<br /><br />$date = '2014-09-29';<br />if($w = date('w', strtotime($date))) $date = date('Y-m-d', strtotime("-$w day $date"));<br /><br />for($i = 0;$i < 7;$i++){<br />$day = date('Y-m-d',strtotime("$i day $date"));<br />echo $day."(".getWeek($day).")\n";<br />}
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template