Maximum Year in Expiry Date of Credit Card

前端 未结 10 880
情话喂你
情话喂你 2021-01-30 02:30

Various online services have different values for maximum year of expiry, when it comes to Credit Cards.

For instance:

  • Basecamp: +15 years (2025)
10条回答
  •  温柔的废话
    2021-01-30 03:22

    While the second example runs twice as quickly as the first you are still getting the date and extracting the year from it 20 times rather than 40 times. A better unrolling of the loop is:

    $StartDate=date('Y');
    $EndDate=$StartDate+21;
    for($i=$StartDate;$i<$EndDate;$i++){
        echo "\n";
    

    That will be about 20 times faster than the twice as fast example and also addresses a minor bug in the original code in that the year could change from one fetching of the date to the next leading to unexpected, though in this case harmless, results.

提交回复
热议问题