Guest User

Untitled

a guest
Oct 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. <?php
  2. $year = 2018;
  3. $month = 12;
  4. $first_day_of_month = "$year-$month-01";
  5. $ts = strtotime($first_day_of_month);
  6. $day_of_week_number = date("w", $ts); // 0-6
  7. $last_day_of_month = date('t', $ts); // e.g. 31
  8.  
  9. $days = range(1, $last_day_of_month);
  10. $grid = array_fill(0, 42, null);
  11. array_splice($grid, $day_of_week_number, count($days), $days);
  12. $grid = array_chunk($grid, 7);
  13.  
  14. echo '<table>';
  15. echo '<thead><tr><th>';
  16. echo implode('</th><th>', ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']);
  17. echo '</th></tr></thead><tbody>';
  18. foreach($grid as $row) {
  19. echo '<tr><td>' . implode('</td><td>', $row) . '</td></tr>';
  20. }
  21. echo '</tbody></table>';
Add Comment
Please, Sign In to add comment