Re: if(date("Y-m-d") >

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 10 Jan 2005 13:08:28 -0500, John Taylor-Johnston
<taylorjo@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
> Hi,
> I would like some help to improve this script. I'm a teacher with a schedule of 17 weeks.
> Instead of using if(date("Y-m-d") >= $week3)  I would like to do a "for i = 1 to 17" and if the current date date("Y-m-d") = week[i] I would like to echo "This is week $week[i]";
> 
> Can someone show me how please?

Ok, let me take another stab at this and answer the actual question
you asked.  What can I say, I haven't had my coffee this morning.  :)

Try this code:

$weeks = array ("20050107", "20050110", "20050115");

for ($i = count($weeks) - 1;  $i >= 0;  $i--)
{
	if (date ("Ymd") >= $weeks[$i])
	{
		print "This is week " . ($i + 1);
		break;
	}
}

It counts backwards, since you'll want to test the latest week first. 
You could count forward in the for loop if you create the weeks array
with the weeks counting down.  I don't particuarly like having a break
in the loop, but it gets the job done.  If you didn't have it in
there, you would see the print statement for every week that has
passed, as opposed to the current one.

Was this a better answer?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux