0

So i have this array in my indexController

 $numbers = [
        'prime' => [2, 3, 5, 7, 11],
        'fibonacci' =>  [1, 1, 2, 3, 5],
        'triangular' => [1, 3, 6, 10, 15]
    ];

And i tried outputing it in the render function like this

'primes' => $numbers['prime']

and like this

$primes = $numbers['prime'];
'primes' => $primes

and in my index.html.twig i just have this simple call

    {{ primes }}

Exception

An exception has been thrown during the rendering of a template ("Notice: Array to string conversion").

1
  • you should use tags like {%for%} to show the array elements. if you have many arrays you can write a filter for their representing . Commented Sep 29, 2018 at 10:57

1 Answer 1

2

Do you want to print that array? You must use a bucle for that.

{% for item in primes %}
    {{ item }}
{% endfor %}
Sign up to request clarification or add additional context in comments.

1 Comment

I may have over complicated things, yes this work. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.