Попробуйте это.Я объяснил код столько, сколько мог.Ваш вопрос был слишком широким, поэтому я не могу точно ответить на вопрос.Вы спросили, КАК создать вывод, и вот как именно.
Вывод почти идентичен тому, что вы просили:
<style>
th, td { border: 1px solid gray; }
th { height:20px;}
/* here I'm giving borders to the grid, and a default height so 2nd line doesn't collapse */
</style>
<?php
//settings:
$month = 5;
$year = 2018;
$ymd = $year . '-' . str_pad($month,2,"0",STR_PAD_LEFT); //this trows 2018-05-01
$lastDay = date('d', strtotime( $ymd . '-01 + 1 month - 1 day')); //I calculate the last day of the month (in this case, 31)
//title:
echo date('M Y', strtotime($ymd)); //print month and year (May 2018)
//space:
echo '<br><br>';
//first table:
makeTable(1,15); //call to the function below, days 1 to 15
//space:
echo '<br><br>';
//2nd table:
makeTable(16,$lastDay); //call to the function below, days 15 to last day
function makeTable($from,$to){
global $month;
//begin table:
echo '<table>';
echo '<tr>';
//first row with dates:
for($d=$from; $d<=$to; $d++) {
//here I create each cell of first row
echo '<th>' . str_pad($d,2,"0",STR_PAD_LEFT) . '-' . str_pad($month,2,"0",STR_PAD_LEFT) . '</th>';
}
echo '</tr><tr>';
//second row blank:
for($d=$from; $d<=$to; $d++) {
//same as above but without text inside the cell
echo '<th> </th>';
}
//end table:
echo '</tr>';
echo '</table>';
}
?>