array.test 733B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. --TEST--
  2. Twig supports array notation
  3. --TEMPLATE--
  4. {# empty array #}
  5. {{ []|join(',') }}
  6. {{ [1, 2]|join(',') }}
  7. {{ ['foo', "bar"]|join(',') }}
  8. {{ {0: 1, 'foo': 'bar'}|join(',') }}
  9. {{ {0: 1, 'foo': 'bar'}|keys|join(',') }}
  10. {# nested arrays #}
  11. {% set a = [1, 2, [1, 2], {'foo': {'foo': 'bar'}}] %}
  12. {{ a[2]|join(',') }}
  13. {{ a[3]["foo"]|join(',') }}
  14. {# works even if [] is used inside the array #}
  15. {{ [foo[bar]]|join(',') }}
  16. {# elements can be any expression #}
  17. {{ ['foo'|upper, bar|upper, bar == foo]|join(',') }}
  18. {# arrays can have a trailing , like in PHP #}
  19. {{
  20. [
  21. 1,
  22. 2,
  23. ]|join(',')
  24. }}
  25. --DATA--
  26. return array('bar' => 'bar', 'foo' => array('bar' => 'bar'))
  27. --EXPECT--
  28. 1,2
  29. foo,bar
  30. 1,bar
  31. 0,foo
  32. 1,2
  33. bar
  34. bar
  35. FOO,BAR,
  36. 1,2