我有一个来自$Infor = $this->StudentFeeUtil->getPaymentPlanDetails($currentSessionID); pr($Infor)的数组
Array
(
[0] => Array
(
[PaymentPlan] => Array
(
[id] => 16
[payment_plan] => 35
[submission_date] => 2022-11-30
[intake_id] => 1263
[session_id] => 1019
)
)
[1] => Array
(
[PaymentPlan] => Array
(
[id] => 15
[payment_plan] => 35
[submission_date] => 2022-10-31
[intake_id] => 1263
[session_id] => 1019
)
)
[2] => Array
(
[PaymentPlan] => Array
(
[id] => 14
[payment_plan] => 30
[submission_date] => 2022-09-30
[intake_id] => 1263
[session_id] => 1019
)
)
)我想遍历这个数组,并将submission_date与当前日期$now = new DateTime();进行比较。如果当前日期,$now小于或等于$submission_date,而$currentBalance大于0,则执行一些操作。基本上,我想要这样的东西:
// Check if student has balance
if ($now <= $Infor[0]['PaymentPlan']['submission_date'] && $currentBalance > 0) {
// Do something
echo " Tell student to pay up balance!";
} else if ($now <= $Infor[1]['PaymentPlan']['submission_date'] && $currentBalance > 0){
// Do something
echo " Tell student to pay up balance!";
} else if ($now <= $Infor[2]['PaymentPlan']['submission_date'] && $currentBalance > 0){
// Do something
echo " Tell student to pay up balance!";
}如何使用foreach()实现这一目标?我正在使用CakePHP-2和PHP5.6。我不知道如何才能最好地实现这一点。
发布于 2022-08-20 10:27:45
假设$now是一个类似于2022-08-20的日期,您可以像下面这样使用foreach,其中$row是每一行的值(这是一个数组),并像通常的数组键访问一样访问submission_date。
<?php
foreach($Infor as $row){
if($currentBalance > 0 && strtotime($now) <= strtotime($row['PaymentPlan']['submission_date'])){
// Do something
echo " Tell student to pay up balance!";
}
}https://stackoverflow.com/questions/73425368
复制相似问题