大家好,我有这样的东西,我想将每个对象的“数字”相乘。例如 2(第一个对象编号)x3(第二个对象编号)=6(答案应该是 6)有人知道怎么做吗?数组并不总是相同的。这里它有 2 个对象,但可以更改。
[{"id":7,"date":"2020-03-14","number":2},{"id":20,"date":"2020-03-15","number":3}]
更新的答案(工作)
foreach ($studentDetail as $student){
$number = calendar::where('student_id','=',$student['id'])
->where('date','>=',$jsonData->checkin)
->where('date','<',$jsonData->checkout)
->get();
Log::info($number );
$multiplied= $number ->reduce(function ($carry, $item) {
return $carry * $item->number;
}, 1);
Log::info($multiplied);
}
DIEA