Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print arrays inside array by Laravel blade?

My function returns an array to a variable in laravel blade page like this :

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 by using something like foreach. Consider that their children's numbers are not specified, it is impossible to do that inside of my function. It is important to me to be done in blade. How can I do that?

like image 973
narsis fe Avatar asked Jun 29 '15 09:06

narsis fe


2 Answers

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

Example:

{{ print_r($array) }}
like image 117
xxxbence Avatar answered Sep 30 '22 19:09

xxxbence


As this is very old issue but I found json directive very useful.

<pre>
    <code>
        @json($array);
    </code>
</pre>
like image 44
Tushar Vaghela Avatar answered Sep 30 '22 17:09

Tushar Vaghela