Skip to content

Instantly share code, notes, and snippets.

@haisum
Created March 5, 2015 08:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haisum/49704fc2a1944014cae1 to your computer and use it in GitHub Desktop.
Save haisum/49704fc2a1944014cae1 to your computer and use it in GitHub Desktop.
Loop through years, months and days in php for dropdown
<?php //All months
for($i=1;$i<=12;$i++) {?>
<option value="<?=$i?>"><?=date("F", strtotime("2001-" . $i . "-25"))?></option>
<?php } ?>
<?php
//past 8 years
for($i=0;$i<8;$i++) {?>
<option value="<?=$i?>"><?=date("Y", strtotime("-$i years"))?></option>
<?php } ?>
<?php
//days
for($i=1;$i<=31;$i++) {?>
<option value="<?=$i?>"><?=$i?></option>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment