我有按类别排序的数据:
$( document ).on( "click", "#formSubmit", function() {
console.log( 'Button Clicked' );
});
我喜欢用刀片打印它
Category 1, Product 1, Amount
Category 1, Product 2, Amount
Category 2, Product 3, Amount
答案 0 :(得分:0)
我假设$ categories是带索引类别,产品和数量的已排序多维数组。
@for ($i = 0; $i < count($categories) ; $i++)
<?php $category_product_toatl=0; ?>
{{ $categories[$i]['category'] }}
{{ $categories[$i]['product'] }} {{ $categories[$i]['amount']}}
<?php
$category_product_total= $category_product_total+ $categories[$i]['amount'];
?>
@for ($j = $i+1; $j < count($categories) ; $j++)
@if($categories[$i]['category']== $categories[$j]['category'])
{{ $categories[$j]['product'] }} {{ $categories[$j]['amount']}}
<?php
$category_product_total= $category_product_total+ $categories[$j]['amount'];
?>
@else
break;
@endif
@endfor
Total Amount of {{ $category[$i] }} : {{ $category_product_total }}
@endfor