php - 获取最大值和最小值,如果值相同,则只打印一个值,Laravel Blade
问题描述
从数组中获取最大值和最小值,如果值相同,则只打印一个值。错误:我在 foreach 中获取所有价格值,例如,Rs 120 120 120 120 120 120
<?php
$maxprice = $product_attributes->max('price');
$minprice = $product_attributes->min('price'); ?>
@foreach($product_attributes->sortBy('price') as $attribute)
@if($maxprice === $minprice )
{{ $attribute->price }}
@endif
@endforeach
解决方案
如果您需要从收藏中找到max
并重视。min
$max = $product_attributes->max('price');
$min = $product_attributes->min('price');
@foreach($product_attributes->sortBy('price') as $attribute)
@if($max === $min )
{{ $attribute->price }}
@endif
@endforeach
推荐阅读
- maatwebsite-excel - maatwebsite 如何将边框显示为简单的线条?
- python - 是否可以在 Python 中使用 leastsq() 来解决多类问题?
- prolog - 是否可以使用“;” 在 SWI-Prolog 的查询中?
- laravel - musonza/聊天供应商买家切换器定制
- mysql - 如何根据列给出行号?
- android - 在constraintlayout中查看键盘弹出android上的重叠
- networking - MSS协商的正式解释是什么?
- php - 注册表单的未定义索引PHP
- azure - 如何在 azure pay as you go 订阅中获取指定开始/结束日期的 Azure 资源使用详细信息
- python - Pandas AttributeError:“DataFrame”对象没有属性“Timestamp”