Ben çıkışı şöyle geçerli tarihten sonraki 12 ay boyunca tarihlerini (sadece pazartesi ve salı) bir liste gerekir:
Jan 2010
Tue 12 Jan 2010
Mon 18 Jan 2010
Tue 19 Jan 2010
Mon 25 Jan 2010
Feb 2010
Tue 02 Feb 2010
Mon 08 Feb 2010
Tue 09 Feb 2010
Mon 15 Feb 2010
Tue 16 Feb 2010
Mon 22 Feb 2010
Mar 2010
Tue 09 Mar 2010
Mon 15 Mar 2010
Tue 16 Mar 2010
...
I strtotime ve sonraki 52 hafta boyunca döngü düşündüm PHP için yeni olan gitmek için en iyi yoldur.
$blockedDatesInput = "08 Mar 2010,12 Apr 2010"; // dont show these dates
$blockedDates = explode ("," , $blockedDatesInput); // convert to array
$currentMonth = ""; // current month marker
// loop over the next 52 weeks to find Mondays and Tuesdays
for($i=0; $i<=52; $i++){
// build the month header
$monthReference = date("M Y", strtotime('+'.$i.' Week'));
// check if date exists in $blockeddate
if (!in_array(date("d M Y", strtotime('+'.$i.' Monday')), $blockedDates) ||
!in_array(date("d M Y", strtotime('+'.$i.' Tuesday')), $blockedDates) ) {
// check if we have to show a new month
if(strcmp($monthReference, $currentMonth) <> 0){
echo $monthReference.'<br />',"\n";
}else{
// output the dates
echo date("D d M Y", strtotime('+'.$i.' Monday')).'<br />',"\n";
echo date("D d M Y", strtotime('+'.$i.' Tuesday')).'<br />',"\n";
}
$currentMonth = date("M Y", strtotime('+'.$i.' Week'));
}
}
Ancak benim kodundan çıktı
Jan 2010
Mon 18 Jan 2010
Tue 12 Jan 2010
Mon 25 Jan 2010
Tue 19 Jan 2010
Feb 2010
Mon 08 Feb 2010
Tue 02 Feb 2010
Mon 15 Feb 2010
Tue 09 Feb 2010
Mon 22 Feb 2010
Tue 16 Feb 2010
Mar 2010
Mon 08 Mar 2010
Tue 02 Mar 2010
Mon 15 Mar 2010
Tue 09 Mar 2010
Mon 22 Mar 2010
Tue 16 Mar 2010
Mon 29 Mar 2010
Tue 23 Mar 2010
Gördüğünüz gibi tarihler doğru sırayla değildir ve ben burada yanlış gidiyorum bir kayıp am.
Bunu çözmek için daha şık / basit bir yolu var mı?
Kullanılan PHP sürümü 5.2.11 ve yakında :-( 5.3 her zaman olacak hiçbir umudu
Yardımlarınız için teşekkürler.
Code below modification as suggested by Aly. Changed the computer date from Tue, 12/01/2010 to Wed, 13/01/2010 to test the output.
$blockedDatesInput = "08 Mar 2010,12 Apr 2010"; // dont show these dates
$blockedDates = explode ("," , $blockedDatesInput); // convert to array
$currentMonth = ""; // current month marker
// loop over the next 52 weeks to find Mondays and Tuesdays
for($i=0; $i<=52; $i++){
// build the month header
$monthReference = date("M Y", strtotime('+'.$i.' Week'));
// check if date exists in $blockeddate
if (!in_array(date("d M Y", strtotime('+'.$i.' Monday')), $blockedDates) ||
!in_array(date("d M Y", strtotime('+'.$i.' Tuesday')), $blockedDates) ) {
// check if we have to show a new month
if(strcmp($monthReference, $currentMonth) <> 0){
echo $monthReference.'<br />',"\n";
}else{
// output the dates (changed the order as suggested by Aly)
echo date("D d M Y", strtotime('+'.$i.' Tuesday')).'<br />',"\n";
echo date("D d M Y", strtotime('+'.$i.' Monday')).'<br />',"\n";
}
$currentMonth = date("M Y", strtotime('+'.$i.' Week'));
}
}
Çıktı yine yanlış sırayla.
Jan 2010
Tue 19 Jan 2010
Mon 18 Jan 2010
Tue 26 Jan 2010
Mon 25 Jan 2010
Feb 2010
Tue 09 Feb 2010
Mon 08 Feb 2010
Tue 16 Feb 2010
Mon 15 Feb 2010
Tue 23 Feb 2010
Mon 22 Feb 2010