Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to create installment table
<?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