TT calendar library About the month arrays used by this library
About the month arrays used by this library

If you look at a calendar, you will see that any month can be represented in a table 7 days wide by 6 weeks high. If you represent each of the boxes in such a table as sequential numbers, you get something like this:

Days-->
w
e
e
k
s
|
|
V
1234567
891011121314
15161718192021
22232425262728
29303132333435
36373839404142

(If 6 weeks sounds a little longer than a month, consider this: if the first day of a 31 day month lies on the last day of a week, the last day of that month lies on the second day of the 5th week afterwards, i.e. in the 6th week overall.)

If you now make a PHP array where the numbers in each box in the table above form the keys and the days of the month that you want to appear in each box form the values, you can represent the way any month appears on your calendar in that array.
For example, March 2004 appears on a calendar like this, assuming the days are represented from Sunday to Saturday:

123456
78910111213
14151617181920
21222324252627
28293031

So a PHP array to represent March 2004 would be represented like this:

Array
(
    [2] => 1 
    [3] => 2 
    [4] => 3 
    [5] => 4 
    [6] => 5 
    [7] => 6 
    [8] => 7 
    [9] => 8 
    [10] => 9 
    [11] => 10 
    [12] => 11 
    [13] => 12 
    [14] => 13 
    [15] => 14
    [16] => 15 
    [17] => 16 
    [18] => 17 
    [19] => 18 
    [20] => 19 
    [21] => 20 
    [22] => 21 
    [23] => 22 
    [24] => 23 
    [25] => 24 
    [26] => 25 
    [27] => 26 
    [28] => 27 
    [29] => 28 
    [30] => 29 
    [31] => 30 
    [32] => 31 
)

The TTCalendar library represents months in an array like this. The aim of the library is to provide the functionality to do more than just draw a simple calendar table, so the array format that it uses holds slightly more information than the array above. Instead of having a single numerical value, each key holds an array of its own which can contain 3 values. The value "num" is the calendar date, "col" is the background colour of the table cell containing the date and "link" is the URI to which the date is linked by an anchor tag. In addition the month and year in question are stored, along with an array containing the day names or abbreviations for the column headings.
Thus for example an array for March 2004 with the 10th to the 19th coloured magenta and linked to "index.html" would appear as follows:

Array
(
    [2] => Array( [num] => 1 )
    [3] => Array( [num] => 2 )
    [4] => Array( [num] => 3 )
    [5] => Array( [num] => 4 )
    [6] => Array( [num] => 5 )
    [7] => Array( [num] => 6 )
    [8] => Array( [num] => 7 )
    [9] => Array( [num] => 8 )
    [10] => Array( [num] => 9 )
    [11] => Array( [num] => 10 [col] => #ff00ff [link] => index.html )
    [12] => Array( [num] => 11 [col] => #ff00ff [link] => index.html )
    [13] => Array( [num] => 12 [col] => #ff00ff [link] => index.html )
    [14] => Array( [num] => 13 [col] => #ff00ff [link] => index.html )
    [15] => Array( [num] => 14 [col] => #ff00ff [link] => index.html )
    [16] => Array( [num] => 15 [col] => #ff00ff [link] => index.html )
    [17] => Array( [num] => 16 [col] => #ff00ff [link] => index.html )
    [18] => Array( [num] => 17 [col] => #ff00ff [link] => index.html )
    [19] => Array( [num] => 18 [col] => #ff00ff [link] => index.html )
    [20] => Array( [num] => 19 [col] => #ff00ff [link] => index.html )
    [21] => Array( [num] => 20 )
    [22] => Array( [num] => 21 )
    [23] => Array( [num] => 22 )
    [24] => Array( [num] => 23 )
    [25] => Array( [num] => 24 )
    [26] => Array( [num] => 25 )
    [27] => Array( [num] => 26 )
    [28] => Array( [num] => 27 )
    [29] => Array( [num] => 28 )
    [30] => Array( [num] => 29 )
    [31] => Array( [num] => 30 )
    [32] => Array( [num] => 31 )
    [month] => 3
    [year] => 2004
    [daynames] => Array ( [0] => S [1] => M [2] => T [3] => W [4] => T [5] => F [6] => S )
)

The array above would be rendered into HTML as follows (table border set to 1 for clarity):

SMTWTFS
123456
78910111213
14151617181920
21222324252627
28293031

About the demo Contents Software licence