【发布时间】:2020-01-28 14:01:21
【问题描述】:
我有一组客户,其中包含一组嵌套的付款。
"customer_1" => array:4 [▼
0 => "211.79"
1 => "206.20"
2 => "0.00"
3 => "0.00"
4 => "220.90"
]
"customer_2" => array:4 [▼
0 => "0.00"
1 => "0.00"
2 => "0.00"
3 => "0.00"
4 => "220.90"
]
我需要为每个客户计算连续付款的金额,从数组顶部的 0.00 开始。
所以我需要它返回如下内容:
"customer_1" => 0
"customer_2" => 4
我尝试了一堆 while 和 foreach 循环,但无法让它工作:
@php($count = 0)
@foreach($array as $arr)
@if($arr = "0.00")
@php($count = $count + 1)
@else
@continue
@endif
@endforeach
【问题讨论】:
-
不是很清楚,根据你的例子。
"customer_1"的值是211.79+206.20+220.90? -
我需要计数连续的“0.00”付款,而不是付款总和。客户 1 从数组顶部没有连续的“0.00”付款,因此 customer_1 = 0。
-
但我认为
customer_1有两个连续的'0.00',我错了吗? -
正确,但不是从数组的开头。他们的第一笔付款是 211.79,因此计数应为 0。
-
我已经发布了我的答案,请检查一下。