passing arrays to blade and iterating
i have an array that looks like this
array (size=3)
'clients' =>
array (size=4)
'Super Fish' =>
array (size=2)
'totalminutes' => int 49
'totalcost' => float 28.58774
'Swedish Fish' =>
array (size=2)
'totalminutes' => int 16
'totalcost' => float 5.85842
'Aero Fish' =>
array (size=2)
'totalminutes' => int 7
'totalcost' => float 0.29714
'Happy Fish' =>
array (size=2)
'totalminutes' => int 44
'totalcost' => float 18.16224
'totalminutes' => int 116
'totalcost' => float 52.90554
controller code looks like this:
$data = Reports\InternationalCallsReport::create();
return View::make('reports.international-calls')->with('data', $data);
view code
@foreach ( $data as $key => $value )
{{ $key }}
@endforeach
displays my array elements just fine clients, totalminutes, totalcost
but if i try to access the clients array it gives me an array to string conversion error
@foreach ( $data as $key => $value )
{{ $key['clients'] }}
@endforeach
I just want to display the client name their minutes used and cost but no matter how I try to make this happen I cant seem to access them all
Needs loops :
foreach($data['clients'] as $k => $v) {
echo $k . '<br>';
foreach ($v as $key => $value) {
echo $key . ' => ' . $value . '<br>';
}
}
In blade version :
@foreach($data['clients'] as $k => $v)
{{ $k }}
@foreach ($v as $key => $value)
{{ $key . ' => ' . $value }}
@endforeach
@endforeach
Please or to participate in this conversation.