note 100975 deleted from function.strtotime by danbrown

From: Date: Fri, 19 Nov 2010 14:25:19 +0000
Subject: note 100975 deleted from function.strtotime by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-174196@lists.php.net to get a copy of this message
Note Submitter: elitezenithweb AT example DOT com ---- I hope that this function comes useful to someone. <?php function wdates($start = 0, $amount = 10, $format = 'Y', $interval = 'Y', $decrease = true) { // Determining where we should start the dates (In years) $start = ((is_numeric($start)) ? $start : 0); // Accomidating the AMOUNT returned accordignly to the START $amount += $start; // Creating an array of years {$amount} times for($i = $start; $i <= $amount; ++$i) { // Checking the interval to increase/decrease by $int = (($interval == 'D') ? 'day' : (($interval == 'M') ? 'month' : 'year')); // Checking if we are decreasing or increasing $loop = (($decrease == true) ? '-' : '+'); // Creating the appropriate time stampe $tmsp = strtotime($loop . $i . ' ' . $int); // Building the date array $date_arr[] = date($format, $tmsp); } // Returning the date array return $date_arr; } print_r(wdates()); ?> That prints: Array ( [0] => 2010 [1] => 2009 [2] => 2008 [3] => 2007 [4] => 2006 [5] => 2005 [6] => 2004 [7] => 2003 [8] => 2002 [9] => 2001 [10] => 2000 ) While <?php print_r(wdates(12,7)); ?> Prints Array ( [0] => 1998 [1] => 1997 [2] => 1996 [3] => 1995 [4] => 1994 [5] => 1993 [6] => 1992 [7] => 1991 )

« previous php.notes (#174196) next »