我在相关数组中获取了一些数据,请参阅图像数据,
我希望将所有元素分组为party
值。每个阵列可能具有不同的参与方名称,但具有类似参与方的阵列可以在页面中进行分组和显示。
我尝试过的是,我可以成功地将golaRate
和rate
分开,但我需要golaRate
和rate
@foreach($data as $bill_data)
@if(!$bill_data['golaRate'])
{{-- @foreach($bill_data['party'] as $party) --}} --> this the problem here
@foreach($data as $bill_data)
@if(!$bill_data['rate'])
{{-- @foreach($bill_data['party'] as $party) --}}
我正在使用laravel框架。
答案 0 :(得分:1)
我不确定这是否是您的要求,希望这可能有所帮助
<?php
$array = array(
array(
"lotname"=>"456",
"quantity"=>"456",
"rate"=>"5",
"golarate"=>null,
"userId"=>null,
"party"=>"fds",
),
array(
"lotname"=>"456",
"quantity"=>"456",
"rate"=>"5",
"golarate"=>null,
"userId"=>null,
"party"=>"fds",
),
array(
"lotname"=>"456",
"quantity"=>"456",
"rate"=>"5",
"golarate"=>null,
"userId"=>null,
"party"=>"bbb",
),
array(
"lotname"=>"456",
"quantity"=>"456",
"rate"=>"5",
"golarate"=>null,
"userId"=>null,
"party"=>"bbb",
),
);
function groupParty($data)
{
$grouped = [];
foreach ($data as $value) {
$grouped[$value['party']][] = $value;
}
return $grouped;
}
print_r(groupParty($array));
?>