Possible Duplicate:
how to generate monthly days with PHP?
With PHP, given a month in this format: 10 - October, 11 - November, how would I populate an array where the keys represent each day for the given month.
So,
e.g for February you'd have an array with keys 1-28.
You can use this function:
function dates_month($month, $year) {
$num = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$dates_month = array();
for ($i = 1; $i <= $num; $i++) {
$mktime = mktime(0, 0, 0, $month, $i, $year);
$date = date("d-M-Y", $mktime);
$dates_month[$i] = $date;
}
return $dates_month;
}
echo"<pre>";
print_r(dates_month(2, 2012));
echo"</pre>";
$date = '02 February';
$days = array_fill_keys(
range(1, date('t', gmmktime(0, 0, 0, (integer) $date, 1))),
NULL
);
Assumption, for this year (else February could be 28 or 29)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With