在视图中我有这个foreach:
@foreach($selectedRtypes as $k => $selectedRtype)
@foreach(range(1,$selectedRtype['quantity']) as $val)
....
@endforeach
@endforeach
如果用户选择的所有注册类型的总价格> 1,我想在刀片视图中显示一些html。 0
你知道如何实现这一目标吗?
“{{dd($ selectedRtypes)}}”显示:
array:2 [▼
"general" => array:6 [▼
"quantity" => "2"
"price" => 5
"subtotal" => 10
"total" => 10
"questions" => Collection {#243 ▼
#items: array:1 [▶]
}
"id" => 1
]
"plus" => array:6 [▼
"quantity" => "1"
"price" => 10
"subtotal" => 10
"total" => 20
"questions" => Collection {#247 ▼
#items: []
}
"id" => 2
]
我不知道下面的内容是否正确,因为只检查一种注册类型的价格:
@foreach($selectedRtypes as $k => $selectedRtype)
@foreach(range(1,$selectedRtype['quantity']) as $val)
....
@if($selectedRtype['price']>0)
<p>show this html</p>
@endif
@endforeach
@endforeach
答案 0 :(得分:1)
将价格保存在另一个变量中
$price = 0;
$price = $price + $selectedRtype['price'];
然后如果$ price&gt; 0,做点什么