Make Select Sticky

What if we don’t reinvent the wheel, and make use of the built-in “is leap year” that the date object contains, via the ‘L’ format character


function is_leap_year($year) {
    // L is 1 for a leap year, otherwise it's 0
    return date('L', strtotime('01/01/' . $year)) > 0;
}

Indeed, but I’m assuming this is a learning exercise more than anything, otherwise I’d also just use checkdate() as well :stuck_out_tongue:

Wouldn’t that be cheating?

There was a built in way to do this I think, but we are not allowed to use it. We have to write the function myself.

Curses! I knew there was an easier way :wink:

I understand that the entire point there was that I was trying to learn how to use constants, and I wanted to show the instructor that I actually listened to the lecture when he talked about them. I wanted to use a little bit of everything in the program.

Remember this was a FIRST PHP program I have ever written, there are a lot of ways it could be done, but we haven’t even covered arrays yet and multi-demential arrays are another story completely. The first program used arrays because that assignment was allready written for one combo box.

I used both ways. I was trying to learn how to make a function with a return variable and how to make a function that used a reference. The instructor talked about that similar to ByVal and ByRef in Visual Basic, I was trying to test it out. I wanted to see how the &$ operator worked.

Because I would have gotten an F on the assignment. It was a first PHP assignment and we covered a few operators and “if statements” in the lecture. I was supposed to use those methods we talked about to build the assignment. The instructor told us that there was built in ways to do this but we were not allowed to use them because the entire point of the assignment was to learn how to write a function ourself to see if we understood the code. It would be simple to get that code from a website and copy/paste it. And the 2 lines of code really doesn’t give him anything to grade.

I know the assignment was not perfect but it was the first time ever even using PHP. I’ve never even seen the language before that assignment so it was supposed to be learning different things. It wasn’t going to be professionally done.

I also have to take a UML course and OOP course and those will get the code looking a lot cleaner. I think I did really good since I’ve never even seen PHP before.