0
array:[
{
"tipo": "1",
"ganador": "2",
"premio": "45"
},
{
"tipo": "2",
"ganador": "5",
"premio": "6545"
},
{
"tipo": "3",
"ganador": "8",
"premio": "6654895"
},
]

I need to access all the values ​​and keys of the array and display them in a table. I tried this

<tr>
{% for key in array %}
  <td>{{key}}</td>
{% endfor %}
</tr>

and it doesn't show any value

DarkBee
  • 16,592
  • 6
  • 46
  • 58
  • 1
    Hi. This is in fact not a multidimensional Array but an Array consisting of three JSON-Objects. Please provide the PHP-Code creating this Array. – MadCatERZ Jun 07 '23 at 19:29

1 Answers1

0

First transform your json output to an array:

$array =  json_decode('[
        {
            "tipo": "1",
            "ganador": "2",
            "premio": "45"
        },
        {
            "tipo": "2",
            "ganador": "5",
            "premio": "6545"
        },
        {
            "tipo": "3",
            "ganador": "8",
            "premio": "6654895"
        }
     ]', true);

Then you can loop in twig:

{% for array_key in array %}
    {% for key, value in array_key %}
        {{ key }} - {{ value }}<br>
    {% endfor %}
{% endfor %}
FF MM
  • 138
  • 9