Twig "in" statement with an array of SimpleXMLElement and keys

Here I have a problem corresponding to the SimpleXMLElement "name" attribute matching keys in an array. When I return the result of the attribute corresponding to the string key, invoking the array key, the result will be true, as expected. But when I try to give it a match using the in operator, the result will be false.

Twig:

{{ dump(options|keys) }}
{% for tense in verbXML %}
{{ dump(tense.attributes.name) }}
{{ dump(tense.attributes.name == (options|keys)[1]) }}
{{ dump(tense.attributes.name in options|keys) }}
{% endfor %}

Result:

   array:2 [▼
      0 => "neg-imperative"
      1 => "present"
    ]

    SimpleXMLElement {#835 ▼
      +"0": "present"
    }

    true

    false
+4
source share
1 answer

As Alain Temblo suggested, using the answer (tense.attributes.name ~ '') in options|keyswas the answer. Thank!

+1
source

All Articles