title: Create an array with Twig
body: <p>I have this in PHP:</p>
  
  <pre><code>$units = array();
  foreach ($popPorts as $port) {
  $units[$port-&gt;getFrameNo()][$port-&gt;getSlotNo()][$port-&gt;getPortNo()] = $port-&gt;getPortNo();
  }
  </code></pre>
  
  <p>How can I achieve the same in twig?</p>
  
  <p>I have tried this so far:</p>
  
  <pre><code>{% set frames = [] %}
  {% for row in object.popPorts %}
      {% set frames[row.frameNo][row.slotNo][row.portNo] = row.portNo %}
  {% endfor %}
  {{ dump(frames) }}
  </code></pre>
  
  <p>But then I get an error:</p>
  
  <blockquote>
    <p>Unexpected token "punctuation" of value "[" ("end of statement block"
    expected).</p>
  </blockquote>
  
  <p>The output should be like this:</p>
  
  <pre><code>array (size=3)
    (frame) 1 =&gt; 
      array (size=2)
        (slot) 1 =&gt;
          array (size=4)
            0 =&gt; (port) 26
            1 =&gt; (port) 27
            2 =&gt; (port) 28
            3 =&gt; (port) 29
        (slot) 5 =&gt;
          array (size=2)
            0 =&gt; (port) 31
            1 =&gt; (port) 34
    (frame) 2 =&gt; 
      array (size=1)
        (slot) 3 =&gt;
          array (size=1)
            0 =&gt; (port) 32
    (frame) 3 =&gt; 
      array (size=1)
        (slot) 6 =&gt;
          array (size=1)
            0 =&gt; (port) 33
  </code></pre>