note 83564 deleted from function.mktime by derick

From: Date: Sat, 26 Jul 2008 10:07:46 +0000
Subject: note 83564 deleted from function.mktime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142781@lists.php.net to get a copy of this message
Note Submitter: Scott Wallace ---- Here's a function I made to make an array containing all days in a given year: <?php # Usage: generateYearArray(int $fyear); # $fyear is the year that you want dates for. function generateYearArray($fyear) { $feb = cal_days_in_month(CAL_GREGORIAN, 2, $fyear); $daysInYear = ($feb === 29) ? 366 : 365; $array = array(); while ($daysInYear > 0) { $array[] = date("Y-m-d", mktime(0, 0, 0, 1, $daysInYear, $fyear)); $daysInYear--; } sort($array); return $array; } ?> Example: generateYearArray(2008); should return an array like: Array( [0] => "2008-01-01", [1] => "2008-01-02", ... [363] => "2008-12-29", [364] => "2008-12-30", [365] => "2008-12-31" ) This function is released into the public domain.

« previous php.notes (#142781) next »