An Example
Let’s bring most of these functions together into an example. We are going to build a calendar that can display the dates for any month between 1980 and 2010. The user will be able to select both month and year with pull-down menus, and the dates for that month will be organized according to the days of the week. If the input is invalid or absent, we will default to the first day of the current month. To develop our calendar, we will create three classes.
The DateIterator Class
The DateIterator class in Listing 16.4 is responsible for setting a pointer to the beginning of the given month and counting each of its days.
Listing 16.4. The DateIterator Class
1: <?php 2: class DateIterator { 3: public static $ADAY = 86400; 4: private ... |
Get Sams Teach Yourself PHP in 24 Hours, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.