How to print arrays inside an array using Laravel blade?

My function returns an array to a variable on the laravel page of the blade server as follows:

Array ( [id] => 1 [name] => Enterpise [children] => Array ( [0] => Array ( [id] => 2 [name] => name1 [children] => Array ( [0] => Array ( [id] => 5 [name] => name2 [children] => ) [1] => Array ( [id] => 6 [name] => name3 [children] => Array ( [0] => Array ( [id] => 11 [name] => name4 [children] => ) ..... 

Now I want to print these values โ€‹โ€‹inside my page using something like foreach . Consider that their childrenโ€™s numbers are not indicated, this is impossible to do inside my function. It is important for me to do it in the blade. How can i do this?

+8
arrays php laravel blade treeview
source share
4 answers

In click files you can use any php functions like print_r() .

Example:

 {{ print_r($array) }} 
+15
source share

Since this is a very old problem, but I found the json directive very useful.

 <pre> <code> @json($array); </code> </pre> 
+5
source share

You can find a way for your problem:

https://laracasts.com/discuss/channels/general-discussion/passing-arrays-to-blade-and-iterating

Or you can use: {{echo json_encode ($ thearray)}}

but this will print your array as a json encoded string.

0
source share

You can use the PHP directive

 @php echo "<pre>"; print_r($array); echo "</pre>"; @endphp 
0
source share

All Articles