Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use this function to convert entire year into array</p> <pre><code> function year2array($year) { $res = $year &gt;= 1970; if ($res) { // this line gets and sets same timezone, don't ask why :) date_default_timezone_set(date_default_timezone_get()); $dt = strtotime("-1 day", strtotime("$year-01-01 00:00:00")); $res = array(); $week = array_fill(1, 7, false); $last_month = 1; $w = 1; do { $dt = strtotime('+1 day', $dt); $dta = getdate($dt); $wday = $dta['wday'] == 0 ? 7 : $dta['wday']; if (($dta['mon'] != $last_month) || ($wday == 1)) { if ($week[1] || $week[7]) $res[$last_month][] = $week; $week = array_fill(1, 7, false); $last_month = $dta['mon']; } $week[$wday] = $dta['mday']; } while ($dta['year'] == $year); } return $res; } </code></pre> <p>Call it like</p> <pre><code>print_r(year2array(2011)); </code></pre> <p>You'll see this in source (months->weeks->days):</p> <pre><code>Array ( [1] =&gt; Array ( [0] =&gt; Array ( [1] =&gt; [2] =&gt; [3] =&gt; [4] =&gt; [5] =&gt; [6] =&gt; 1 [7] =&gt; 2 ) [1] =&gt; Array ( [1] =&gt; 3 [2] =&gt; 4 [3] =&gt; 5 [4] =&gt; 6 [5] =&gt; 7 [6] =&gt; 8 [7] =&gt; 9 ) [2] =&gt; Array ( [1] =&gt; 10 [2] =&gt; 11 [3] =&gt; 12 [4] =&gt; 13 [5] =&gt; 14 [6] =&gt; 15 [7] =&gt; 16 ) [3] =&gt; Array ( [1] =&gt; 17 [2] =&gt; 18 [3] =&gt; 19 [4] =&gt; 20 [5] =&gt; 21 [6] =&gt; 22 [7] =&gt; 23 ) [4] =&gt; Array ( [1] =&gt; 24 [2] =&gt; 25 [3] =&gt; 26 [4] =&gt; 27 [5] =&gt; 28 [6] =&gt; 29 [7] =&gt; 30 ) [5] =&gt; Array ( [1] =&gt; 31 [2] =&gt; [3] =&gt; [4] =&gt; [5] =&gt; [6] =&gt; [7] =&gt; ) ) [2] =&gt; Array ( [0] =&gt; Array ( [1] =&gt; [2] =&gt; 1 [3] =&gt; 2 [4] =&gt; 3 [5] =&gt; 4 [6] =&gt; 5 [7] =&gt; 6 ) [1] =&gt; Array ( [1] =&gt; 7 [2] =&gt; 8 [3] =&gt; 9 [4] =&gt; 10 [5] =&gt; 11 [6] =&gt; 12 [7] =&gt; 13 ) [2] =&gt; Array ( [1] =&gt; 14 [2] =&gt; 15 [3] =&gt; 16 [4] =&gt; 17 [5] =&gt; 18 [6] =&gt; 19 [7] =&gt; 20 ) [3] =&gt; Array ( [1] =&gt; 21 [2] =&gt; 22 [3] =&gt; 23 [4] =&gt; 24 [5] =&gt; 25 [6] =&gt; 26 [7] =&gt; 27 ) [4] =&gt; Array ( [1] =&gt; 28 [2] =&gt; [3] =&gt; [4] =&gt; [5] =&gt; [6] =&gt; [7] =&gt; ) ) [3] =&gt; Array ( [0] =&gt; Array ( [1] =&gt; [2] =&gt; 1 [3] =&gt; 2 [4] =&gt; 3 [5] =&gt; 4 [6] =&gt; 5 [7] =&gt; 6 ) [1] =&gt; Array ( [1] =&gt; 7 [2] =&gt; 8 [3] =&gt; 9 [4] =&gt; 10 [5] =&gt; 11 [6] =&gt; 12 [7] =&gt; 13 ) [2] =&gt; Array ( [1] =&gt; 14 [2] =&gt; 15 [3] =&gt; 16 [4] =&gt; 17 [5] =&gt; 18 [6] =&gt; 19 [7] =&gt; 20 ) [3] =&gt; Array ( [1] =&gt; 21 [2] =&gt; 22 [3] =&gt; 23 [4] =&gt; 24 [5] =&gt; 25 [6] =&gt; 26 [7] =&gt; 27 ) [4] =&gt; Array ( [1] =&gt; 28 [2] =&gt; 29 [3] =&gt; 30 [4] =&gt; 31 [5] =&gt; [6] =&gt; [7] =&gt; ) ) [4] =&gt; Array ( [0] =&gt; Array ( [1] =&gt; [2] =&gt; [3] =&gt; [4] =&gt; [5] =&gt; 1 [6] =&gt; 2 [7] =&gt; 3 ) [1] =&gt; Array ( [1] =&gt; 4 [2] =&gt; 5 [3] =&gt; 6 [4] =&gt; 7 [5] =&gt; 8 [6] =&gt; 9 [7] =&gt; 10 ) [2] =&gt; Array ( [1] =&gt; 11 [2] =&gt; 12 [3] =&gt; 13 [4] =&gt; 14 [5] =&gt; 15 [6] =&gt; 16 [7] =&gt; 17 ) [3] =&gt; Array ( [1] =&gt; 18 [2] =&gt; 19 [3] =&gt; 20 [4] =&gt; 21 [5] =&gt; 22 [6] =&gt; 23 [7] =&gt; 24 ) [4] =&gt; Array ( [1] =&gt; 25 [2] =&gt; 26 [3] =&gt; 27 [4] =&gt; 28 [5] =&gt; 29 [6] =&gt; 30 [7] =&gt; ) ) [5] =&gt; Array ( [0] =&gt; Array ( [1] =&gt; [2] =&gt; [3] =&gt; [4] =&gt; [5] =&gt; [6] =&gt; [7] =&gt; 1 ) [1] =&gt; Array ( [1] =&gt; 2 [2] =&gt; 3 [3] =&gt; 4 [4] =&gt; 5 [5] =&gt; 6 [6] =&gt; 7 [7] =&gt; 8 ) [2] =&gt; Array ( [1] =&gt; 9 [2] =&gt; 10 [3] =&gt; 11 [4] =&gt; 12 [5] =&gt; 13 [6] =&gt; 14 [7] =&gt; 15 ) [3] =&gt; Array ( [1] =&gt; 16 [2] =&gt; 17 [3] =&gt; 18 [4] =&gt; 19 [5] =&gt; 20 [6] =&gt; 21 [7] =&gt; 22 ) [4] =&gt; Array ( [1] =&gt; 23 [2] =&gt; 24 [3] =&gt; 25 [4] =&gt; 26 [5] =&gt; 27 [6] =&gt; 28 [7] =&gt; 29 ) [5] =&gt; Array ( [1] =&gt; 30 [2] =&gt; 31 [3] =&gt; [4] =&gt; [5] =&gt; [6] =&gt; [7] =&gt; ) ) [6] =&gt; Array ( [0] =&gt; Array ( [1] =&gt; [2] =&gt; [3] =&gt; 1 [4] =&gt; 2 [5] =&gt; 3 [6] =&gt; 4 [7] =&gt; 5 ) [1] =&gt; Array ( [1] =&gt; 6 [2] =&gt; 7 [3] =&gt; 8 [4] =&gt; 9 [5] =&gt; 10 [6] =&gt; 11 [7] =&gt; 12 ) [2] =&gt; Array ( [1] =&gt; 13 [2] =&gt; 14 [3] =&gt; 15 [4] =&gt; 16 [5] =&gt; 17 [6] =&gt; 18 [7] =&gt; 19 ) [3] =&gt; Array ( [1] =&gt; 20 [2] =&gt; 21 [3] =&gt; 22 [4] =&gt; 23 [5] =&gt; 24 [6] =&gt; 25 [7] =&gt; 26 ) [4] =&gt; Array ( [1] =&gt; 27 [2] =&gt; 28 [3] =&gt; 29 [4] =&gt; 30 [5] =&gt; [6] =&gt; [7] =&gt; ) ) [7] =&gt; Array ( [0] =&gt; Array ( [1] =&gt; [2] =&gt; [3] =&gt; [4] =&gt; [5] =&gt; 1 [6] =&gt; 2 [7] =&gt; 3 ) [1] =&gt; Array ( [1] =&gt; 4 [2] =&gt; 5 [3] =&gt; 6 [4] =&gt; 7 [5] =&gt; 8 [6] =&gt; 9 [7] =&gt; 10 ) [2] =&gt; Array ( [1] =&gt; 11 [2] =&gt; 12 [3] =&gt; 13 [4] =&gt; 14 [5] =&gt; 15 [6] =&gt; 16 [7] =&gt; 17 ) [3] =&gt; Array ( [1] =&gt; 18 [2] =&gt; 19 [3] =&gt; 20 [4] =&gt; 21 [5] =&gt; 22 [6] =&gt; 23 [7] =&gt; 24 ) [4] =&gt; Array ( [1] =&gt; 25 [2] =&gt; 26 [3] =&gt; 27 [4] =&gt; 28 [5] =&gt; 29 [6] =&gt; 30 [7] =&gt; 31 ) ) [8] =&gt; Array ( [0] =&gt; Array ( [1] =&gt; 1 [2] =&gt; 2 [3] =&gt; 3 [4] =&gt; 4 [5] =&gt; 5 [6] =&gt; 6 [7] =&gt; 7 ) [1] =&gt; Array ( [1] =&gt; 8 [2] =&gt; 9 [3] =&gt; 10 [4] =&gt; 11 [5] =&gt; 12 [6] =&gt; 13 [7] =&gt; 14 ) [2] =&gt; Array ( [1] =&gt; 15 [2] =&gt; 16 [3] =&gt; 17 [4] =&gt; 18 [5] =&gt; 19 [6] =&gt; 20 [7] =&gt; 21 ) [3] =&gt; Array ( [1] =&gt; 22 [2] =&gt; 23 [3] =&gt; 24 [4] =&gt; 25 [5] =&gt; 26 [6] =&gt; 27 [7] =&gt; 28 ) [4] =&gt; Array ( [1] =&gt; 29 [2] =&gt; 30 [3] =&gt; 31 [4] =&gt; [5] =&gt; [6] =&gt; [7] =&gt; ) ) [9] =&gt; Array ( [0] =&gt; Array ( [1] =&gt; [2] =&gt; [3] =&gt; [4] =&gt; 1 [5] =&gt; 2 [6] =&gt; 3 [7] =&gt; 4 ) [1] =&gt; Array ( [1] =&gt; 5 [2] =&gt; 6 [3] =&gt; 7 [4] =&gt; 8 [5] =&gt; 9 [6] =&gt; 10 [7] =&gt; 11 ) [2] =&gt; Array ( [1] =&gt; 12 [2] =&gt; 13 [3] =&gt; 14 [4] =&gt; 15 [5] =&gt; 16 [6] =&gt; 17 [7] =&gt; 18 ) [3] =&gt; Array ( [1] =&gt; 19 [2] =&gt; 20 [3] =&gt; 21 [4] =&gt; 22 [5] =&gt; 23 [6] =&gt; 24 [7] =&gt; 25 ) [4] =&gt; Array ( [1] =&gt; 26 [2] =&gt; 27 [3] =&gt; 28 [4] =&gt; 29 [5] =&gt; 30 [6] =&gt; [7] =&gt; ) ) [10] =&gt; Array ( [0] =&gt; Array ( [1] =&gt; [2] =&gt; [3] =&gt; [4] =&gt; [5] =&gt; [6] =&gt; 1 [7] =&gt; 2 ) [1] =&gt; Array ( [1] =&gt; 3 [2] =&gt; 4 [3] =&gt; 5 [4] =&gt; 6 [5] =&gt; 7 [6] =&gt; 8 [7] =&gt; 9 ) [2] =&gt; Array ( [1] =&gt; 10 [2] =&gt; 11 [3] =&gt; 12 [4] =&gt; 13 [5] =&gt; 14 [6] =&gt; 15 [7] =&gt; 16 ) [3] =&gt; Array ( [1] =&gt; 17 [2] =&gt; 18 [3] =&gt; 19 [4] =&gt; 20 [5] =&gt; 21 [6] =&gt; 22 [7] =&gt; 23 ) [4] =&gt; Array ( [1] =&gt; 24 [2] =&gt; 25 [3] =&gt; 26 [4] =&gt; 27 [5] =&gt; 28 [6] =&gt; 29 [7] =&gt; 30 ) [5] =&gt; Array ( [1] =&gt; 31 [2] =&gt; [3] =&gt; [4] =&gt; [5] =&gt; [6] =&gt; [7] =&gt; ) ) [11] =&gt; Array ( [0] =&gt; Array ( [1] =&gt; [2] =&gt; 1 [3] =&gt; 2 [4] =&gt; 3 [5] =&gt; 4 [6] =&gt; 5 [7] =&gt; 6 ) [1] =&gt; Array ( [1] =&gt; 7 [2] =&gt; 8 [3] =&gt; 9 [4] =&gt; 10 [5] =&gt; 11 [6] =&gt; 12 [7] =&gt; 13 ) [2] =&gt; Array ( [1] =&gt; 14 [2] =&gt; 15 [3] =&gt; 16 [4] =&gt; 17 [5] =&gt; 18 [6] =&gt; 19 [7] =&gt; 20 ) [3] =&gt; Array ( [1] =&gt; 21 [2] =&gt; 22 [3] =&gt; 23 [4] =&gt; 24 [5] =&gt; 25 [6] =&gt; 26 [7] =&gt; 27 ) [4] =&gt; Array ( [1] =&gt; 28 [2] =&gt; 29 [3] =&gt; 30 [4] =&gt; [5] =&gt; [6] =&gt; [7] =&gt; ) ) [12] =&gt; Array ( [0] =&gt; Array ( [1] =&gt; [2] =&gt; [3] =&gt; [4] =&gt; 1 [5] =&gt; 2 [6] =&gt; 3 [7] =&gt; 4 ) [1] =&gt; Array ( [1] =&gt; 5 [2] =&gt; 6 [3] =&gt; 7 [4] =&gt; 8 [5] =&gt; 9 [6] =&gt; 10 [7] =&gt; 11 ) [2] =&gt; Array ( [1] =&gt; 12 [2] =&gt; 13 [3] =&gt; 14 [4] =&gt; 15 [5] =&gt; 16 [6] =&gt; 17 [7] =&gt; 18 ) [3] =&gt; Array ( [1] =&gt; 19 [2] =&gt; 20 [3] =&gt; 21 [4] =&gt; 22 [5] =&gt; 23 [6] =&gt; 24 [7] =&gt; 25 ) [4] =&gt; Array ( [1] =&gt; 26 [2] =&gt; 27 [3] =&gt; 28 [4] =&gt; 29 [5] =&gt; 30 [6] =&gt; 31 [7] =&gt; ) ) ) </code></pre> <p>So, now it's easy to create month table for every month you need using something like this</p> <pre><code> function month2table($month, $calendar_array) { $ca = 'align="center"'; $res = "&lt;table cellpadding=\"2\" cellspacing=\"1\" style=\"border:solid 1px #000000;font-family:tahoma;font-size:12px;background-color:#ababab\"&gt;&lt;tr&gt;&lt;td $ca&gt;Mo&lt;/td&gt;&lt;td $ca&gt;Tu&lt;/td&gt;&lt;td $ca&gt;We&lt;/td&gt;&lt;td $ca&gt;Th&lt;/td&gt;&lt;td $ca&gt;Fr&lt;/td&gt;&lt;td $ca&gt;Sa&lt;/td&gt;&lt;td $ca&gt;Su&lt;/td&gt;&lt;/tr&gt;"; foreach ($calendar_array[$month] as $month=&gt;$week) { $res .= '&lt;tr&gt;'; foreach ($week as $day) { $res .= '&lt;td align="right" width="20" bgcolor="#ffffff"&gt;' . ($day ? $day : '&amp;nbsp;') . '&lt;/td&gt;'; } $res .= '&lt;/tr&gt;'; } $res .= '&lt;/table&gt;'; return $res; } </code></pre> <p>Use these functions like</p> <pre><code> $calarr = year2array(2011); echo month2table(1, $calarr); // January echo month2table(2, $calarr); // February ... echo month2table(12, $calarr); // December </code></pre> <p>..or put months in <code>for</code> loop.</p> <p>So... e.g. for <strong>January 2011</strong> in your browser you'll see this</p> <p><img src="https://i.stack.imgur.com/K0mw2.gif" alt="enter image description here"></p> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload