Re: Year

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

 



On Fri, February 2, 2007 7:41 pm, Robert Cummings wrote:
>> for ($year = date('Y'); $year <= date('Y') + 10; $year++){
>>   $short_year = $year - 2000;

$short_year = sprintf('%02d', $short_year);

>>   echo "<option value=\"$short_year\">$year</option>\n";
>> }
>>
>> Using the 2-digit year as your value is almost for sure a really Bad
>> Idea, unless you are dealing with legacy software that absolutely
>> needs it...
>
> Sorry Richard, you solution fails since he wants to retain the leading
> zeros on the 2 digit years. Using subtraction and not formatting the
> result will result in the loss of the 0 in 07. Also, why call the
> date()
> function 10 times by embedding it in the loop's terminate condition?

Because 10 calls to date() is chump-change.

If you need to optimize away 10 calls to date() then something is
horribly wrong...

That said, it's pretty trivial to optimize it:
for ($year = date('Y'), $end = date('Y) + 10; $year <= $end; $year++){

If PHP guarantees the order of operations in for(, ; ; ) you could
even use $year instead of date('Y) on the $end assignment.  That's
really getting silly about optimization, however.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
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