purefusion Posted March 14, 2006 Share Posted March 14, 2006 Hey, I'm looking for a [b][i]simple[/i][/b] script that generates the next few Tues/Thurs pair combinations and stores them in a numbered array. Simple enough?For example: If today is Monday the 13, array[1] = Tuesday14, array[2] = Thursday16, etcI would like to have this rule: if today is Tuesday already, start with the next Thursday, and vice-versa.They will be echoed in a loop that generates a drop down box in a form such as:[code] <select name="select"> <option value="tues14">Tuesday</option> <option value="thurs16">Thursday</option> < ... etc ... > </select>[/code]Hoping you can point me along in the direction of simple coding, as something I'd come up with would to too over-coded and would probably take forever to render.Thanks so much! Link to comment https://forums.phpfreaks.com/topic/4899-script-that-generates-the-next-few-tuesthurs-pairs-and-stores-them-in-a-numbered-array/ Share on other sites More sharing options...
Barand Posted March 14, 2006 Share Posted March 14, 2006 try[code]$today = mktime(0,0,0);$arr = array();for ($d=1; $d<=30; $d++) { $dt = strtotime("+$d days", $today); //get day of week $dow = date('w', $dt); // store dateval in array if (($dow==2) || ($dow==4)) $arr[] = $dt;}// print optionsecho "<SELECT name='days'>\n";foreach ($arr as $dt) { printf ("<option value='%s'>%s</option>\n", date('Dd', $dt), date('l j', $dt));}echo "</SELECT>\n";[/code] Link to comment https://forums.phpfreaks.com/topic/4899-script-that-generates-the-next-few-tuesthurs-pairs-and-stores-them-in-a-numbered-array/#findComment-17274 Share on other sites More sharing options...
purefusion Posted March 14, 2006 Author Share Posted March 14, 2006 Works beautifully. I will gleen from it. Barand, you rock! Link to comment https://forums.phpfreaks.com/topic/4899-script-that-generates-the-next-few-tuesthurs-pairs-and-stores-them-in-a-numbered-array/#findComment-17335 Share on other sites More sharing options...
wickning1 Posted March 14, 2006 Share Posted March 14, 2006 That's simple, but does a little extra work. As soon as you find one, most of your work is done. Shouldn't be a big deal either way though.[code]$today = mktime(0,0,0);$arr = array();$adv = 1;for ($d=1; $d<=30; $d += $adv) { $dt = strtotime("+$d days", $today); //get day of week $dow = date('w', $dt); // store dateval in array if (($dow==2) || ($dow==4)) $arr[] = $dt; if ($dow == 2) $adv = 2; if ($dow == 4) $adv = 5;}// print it like Barand showed you[/code] Link to comment https://forums.phpfreaks.com/topic/4899-script-that-generates-the-next-few-tuesthurs-pairs-and-stores-them-in-a-numbered-array/#findComment-17472 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.