Reputation: 1
I have the following function snippets which calculate the bi-monthly payment schedule. I need to be able to ready the values as individual array element to be inserted into MYSQL database. How do I achieve this?
function calculatePaymentSchedule($d1, $months){
$date = new DateTime($d1);
// call second function to add the months
$newDate = $date->add(addMonths($months, $date));
//formats final date to Y-m-d form
$dateReturned = $newDate->format('Y-m-d');
return $dateReturned;
}
$startDate = '2018-5-15';
$duration = 12;
$paymentCount = $duration + 2;
for($i =0; $i < $paymentCount; $i++){
if($i % 2 == 0 && $i != 0){
$final = calculatePaymentSchedule($startDate, $i);
echo $final.'<br>';
}
}
current state output:
2018-07-15
2018-09-15
2018-11-15
2019-01-15
2019-03-15
2019-05-15
Upvotes: 0
Views: 39
Reputation: 1123
initalize array at top:
all_dates = array();
in for loop :
$final = calculatePaymentSchedule($startDate, $i);
array_push($all_dates, $final);
Upvotes: 1