How to Build a Dynamic Credit Card Expiration Year Drop-down using PHP

Check out my other posts and tutorials on Web Development!

Using the code below we can create a dynamic drop-down that will display the current year along with the next five years, eliminating the need to edit static credit card expiration drop-downs every year.

<select name="expiry">
    <option value=''>Year</option>
    <?php 
    for ($i = date('Y'); $i <= date('Y')+5; $i++) {
        echo '<option value="'.$i.'">'.$i.'</option>';
    } ?>
</select> 

One Response to How to Build a Dynamic Credit Card Expiration Year Drop-down using PHP

Leave a Reply

Contact Us

Subscribe

Subscribe to our blog to receive latest news and tutorials on Web Design, Development, SEO, and more!