Im keen to improve my php skills so that my coding is faster and more efficient.
Here is a calendar script i mushed up this morning.
<?php
$month = 9;
$year = 2006;
$date = mktime(12,0,0,$month,1,$year);
//number of days
$dnd = date('t', $date);
//start day
$dsd = date('w', $date);
$days = array('Mon','Tue','Wed','Thu','Fri','Sat','Sun');
echo '<h1>'.date('F Y', $date).'</h1>';
echo '<table>';
echo '<tr>';
foreach($days as $day){
echo '<th>'.$day.'</th>';
}
echo '</tr>';
$tr = 0;
//offset
for($i = $dsd-1; $i > 0; $i--){
if($tr == 0){
echo '<tr>';
}
$tr++;
//offset cell
echo '<td> </td>';
if($tr == 7){
echo '</tr>';
$tr = 0;
}
}
//days
for($i = $dnd; $i > 0; $i--){
if($tr == 0){
echo '<tr>';
}
$tr++;
//day number
$dn++;
echo '<td>'.$dn.'</td>';
if($tr == 7){
echo '</tr>';
$tr = 0;
}
}
//fill
for($i = 7-($dsd+1); $i > 0; $i--){
if($tr == 0){
echo '<tr>';
}
$tr++;
//fill cell
echo '<td> </td>';
if($tr == 7){
echo '</tr>';
$tr = 0;
}
}
echo '</table>';
?>
What changes could I make to improve this code? How are they better from my methods?
Thank you everyone.