作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下函数片段,用于计算双月付款计划。我需要能够将这些值作为单独的数组元素准备好插入到 MYSQL 数据库中。我如何实现这一目标?
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>';
}
}
当前状态输出:
2018-07-15
2018-09-15
2018-11-15
2019-01-15
2019-03-15
2019-05-15
最佳答案
在顶部初始化数组:
all_dates = array();
在 for 循环中:
$final = calculatePaymentSchedule($startDate, $i);
array_push($all_dates, $final);
关于php - 如何将 PHP 函数读入数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51307594/
我是一名优秀的程序员,十分优秀!