Jump to content

Script that generates the next few Tues/Thurs pairs and stores them in a numbered array


purefusion

Recommended Posts

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, etc
I 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
Share on other sites

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 options
echo "<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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.