You Are Here Home > Generating an array of months
DirectorySync is a directory synchronizing and backup utility providing automated, real-time syncing and scheduled, configurable backups at an affordable price.

Generating an array of months

Here is a nice way of doing this:

for( $i = 0; $i < 12; $i++ ) {
    $retval[ $i ] =
       date('M', strtotime('Jan +' .$i .' month'));
}

The real power of this is when you put it in a function like this:

function get_months($format) {
   $retval = array();
   for( $i = 0; $i < 12; $i++ ) {
      $retval[ $i ] =
         date($format, strtotime('Jan +' .$i .' month'));
    }
   return $retval;
}

And calling it like this:

$list_of_months_short_text = get_months('M');
$list_of_months_full_text  = get_months('F');
Generating an array of months
Filed under: PHP,Web Development   Tags: ,   Posted by: Codehead
Do you have any questions? ask here.




No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment