How can I write a leap-year program in one line using PHP?
How can I write a leap-year program in on开发者_JS百科e line using PHP?
This is how to know it using one line of code :)
print (date("L") == 1) ? "Leap Year" : "Not Leap Year";
if (($year % 400 === 0) || (($year % 100 !== 0) && ($year % 4 === 0))) echo "leap";
Since there is no limit in how long a line of code is, unless you are using a code convention like that of Zend Framework, you can use whatever works and write into one line. Of course, depending on the functionality of your leap-year program, this will likely be hard to maintain. I've seen legacy code running over 800 chars with PHP, HTML and CSS intermingled. Eye-bleeding, I can tell you.
echo date("L");
$nextyear = mktime(0, 0, 0, date("m"), date("d"), date("Y")+1);
date("L"); is even shorter.
if(date("L")){
//leap year
} else {
//not leap year
}
精彩评论