Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

richbreton's avatar

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

0 likes
1 reply
bestmomo's avatar
Level 52

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
2 likes

Please or to participate in this conversation.