Loops 循环的symfony2不适用于正确的阵列

Loops 循环的symfony2不适用于正确的阵列,loops,symfony,for-loop,Loops,Symfony,For Loop,情况: {{ trollArray.1 }} {# returns (string) "someValue1" #} {{ trollArray.2 }} {# returns (string) "someValue2" #} 但是,当我想进行for循环时: <p> loop begin </p> {% for key,value in trollArray %} <p> Key : {{ key }} <

情况:

{{ trollArray.1 }} {# returns (string) "someValue1" #}
{{ trollArray.2 }} {# returns (string) "someValue2" #}
但是,当我想进行for循环时:

<p> loop begin </p>
    {% for key,value in trollArray %}
        <p>
            Key : {{ key }} <br>
            Value : {{ value }}
        </p>
    {% endfor %}
<p> loop end </p>

trollArray来自json_encode()。。。我忘了。 所以我解决了这个问题:

array {# compatible format with twig loop - json_decode($array,true) #}
  '1' => string '1'
  '2' => string '2'
  '3' => string '3'
  '4' => string '4'
  '5' => string '5'
  '6' => string '6'
  '7' => string '7'
  '8' => string '8'
  '9' => string '9'
  '0' => string '0'

object(stdClass) {# incompatible format with twig loop - json_decode($array,false) #}
  public '1' => string '1'
  public '2' => string '2'
  public '3' => string '3'
  public '4' => string '4'
  public '5' => string '5'
  public '6' => string '6'
  public '7' => string '7'
  public '8' => string '8'
  public '9' => string '9'
  public '0' => string '0'

trollArraycom从哪里来?如何在控制器中定义数组?
array {# compatible format with twig loop - json_decode($array,true) #}
  '1' => string '1'
  '2' => string '2'
  '3' => string '3'
  '4' => string '4'
  '5' => string '5'
  '6' => string '6'
  '7' => string '7'
  '8' => string '8'
  '9' => string '9'
  '0' => string '0'

object(stdClass) {# incompatible format with twig loop - json_decode($array,false) #}
  public '1' => string '1'
  public '2' => string '2'
  public '3' => string '3'
  public '4' => string '4'
  public '5' => string '5'
  public '6' => string '6'
  public '7' => string '7'
  public '8' => string '8'
  public '9' => string '9'
  public '0' => string '0'