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
$final[] = calculatePaymentSchedule($startDate, $i);so you fill the$finalarray with the individual results and reference the array elements for inserts into your database.