I get some data in an associated array, see image for data,
Here I want to group all elements with party
value. Each array may have different party name but arrays with a similar party to be grouped and displayed in the page.
What I tried is, Here I can successfully separate golaRate
and rate
, but I need specific party name for golaRate
and 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) --}}
am using laravel framework.
I am not sure this is your requirement or not, hope this may help
<?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));
?>