<p>You would use the <a href="http://twig.sensiolabs.org/doc/filters/split.html" rel="nofollow"><code>split</code></a> filter.</p>

<pre><code>{% set fruits = "Apples; Bananas; Tomatoes" | split('; ') %}
</code></pre>

CC BY-SA 3.0
2014-06-14T18:31:57.017Z
Strange why it is shown that my question was viewed only 1 Time...
nicael
CC BY-SA 3.0
2014-06-14T18:36:54.323Z
Of course fruits is MUCH more better and accurately then items. I had some doubts but now in 5 mins I'll accept your answer.
nicael
CC BY-SA 3.0
2014-06-14T18:29:22.613Z
2014-06-14T18:35:02.703Z
2014-06-14T18:35:02.703Z
Bill Criswell
<p>Use <a href="http://twig.sensiolabs.org/doc/filters/split.html" rel="nofollow">Twig's split filter.</a></p>

<pre><code>{{ "Apples; Bananas; Tomatoes"|split('; ') }}
</code></pre>

CC BY-SA 3.0
2014-06-14T18:30:47.553Z
2014-06-14T18:30:47.553Z
Simon Kuran
<p>How can I split (or explode) a Twig string like this:</p>

<pre><code>{% set fruits = "Apples; Bananas; Tomatoes" %}
</code></pre>

<p>into an array like this:</p>

<pre><code>{{ ["Apples", "Bananas", "Tomatoes"] }}
</code></pre>

<templating><filter>
How to split a string into an array
# How to split a string into an array

(Asked by: username_0 on 2014-06-14)

How can I split (or explode) a Twig string like this:
{% set fruits = "Apples; Bananas; Tomatoes" %}

into an array like this:
{{ ["Apples", "Bananas", "Tomatoes"] }}

**Tags:** templating, filter


---

## 2 answers

### Answer by username_1 on 2014-06-14. Score: 5 | Accepted answer

You would use the split filter.
{% set fruits = "Apples; Bananas; Tomatoes" | split('; ') %}

> **Comments:**
> **username_0**: Strange why it is shown that my question was viewed only 1 Time...  
> **username_0**: Of course fruits is MUCH more better and accurately then items. I had some doubts but now in 5 mins I'll accept your answer.  

---

### Answer by username_2 on 2014-06-14. Score: 1

Use Twig's split filter.
{{ "Apples; Bananas; Tomatoes"|split('; ') }}


---

