How to create installment table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function nextMonths( $date ){ | |
$dateArray = [0 => $date]; | |
for( $i=1; $i<=12; $i++){ | |
$new_date = date('Y-m-d', strtotime('+'.$i.' months', strtotime($date) ) ); | |
$next_month = date('Y-m-d', strtotime('last day of next month', strtotime( end($dateArray) ) )); | |
if ( date('m', strtotime($new_date) ) != date('m', strtotime($next_month)) ){ | |
$dateArray[] = $next_month; | |
} else { | |
$dateArray[] = $new_date; | |
} | |
} | |
return $dateArray; | |
} | |
$date = '2016-12-31'; | |
print_r( nextMonths( $date ) ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment