Wednesday, 8 August 2012

How to print last twelve months in dropdown

<?php
$months = array();
for($i = 0; $i < 12; $i++){
  $timestamp = strtotime("-$i month");
  $value =  date('n,Y', strtotime("-$i month"));
  $text  =  date('F Y', strtotime("-$i month")); 
  $months[$value] =  $text;
}
print '<select>';
foreach($months as $value => $text){
    print '<option value="'.$value.'">'.$text.'</option>';
}
print '</select>';
?>

No comments:

Post a Comment