我有一个带有startDate变量的数据数组-我该如何返回带有date变量的对象总数,然后只打印数字?
$date = Todays date
foreach ($results->data as $row) {
$checkDate = $row->startDate;
if(date('Y-m-d', strtotime($row->startDate)) == $date){
Return total of date found
}
}
答案 0 :(得分:1)
只要找到一个计数器,就递增它:
$date = '2019-02-20';
$total = 0;
foreach ($results->data as $row) {
if(date('Y-m-d', strtotime($row->startDate)) == $date){
$total++; // same as $total = $total + 1;
}
}
echo "$date found $total times";