+ 1

How to loop array in array?

I'm using laravel and want to loop data from controller in template. Controller: $post=Post::all(); $data = array (); foreach($posts as $post){ $image=getImage(post->id); $obj=array( "post"=>$post, "image"=>$image); array_push($data, $obj); } In template/blade I would like to: foreach data foreach data["images"] and so on. I've tried several things, but could not figure it out yet. So how would you loop? Asuming 1 post with several images.

21st Jul 2021, 10:51 AM
Fu Foy
Fu Foy - avatar
1 Antwort
0
foreach($posts as $post) { $images = $post["images"]; foreach($images as $image) { // do something } }
24th Jul 2021, 4:03 AM
Nico Ruder
Nico Ruder - avatar