title: Symfony storing results of foreach loop
body: <p>I'm wondering if is it possible to store results of foreach loop.
  I dont know how to explain my question more detailed. </p>
  
  <p>So lets say following gets me 3 different arrays</p>
  
  <pre><code>$events = $this-&gt;getDoctrine()-&gt;getRepository('TestBundle:Events')-&gt;findBy(array('event' =&gt; $eventId));
  </code></pre>
  
  <p><strong><em><code>#name,color#</code></em></strong></p>
  
  <p><strong>1.  Party, pink<br>
  2.  Poolparty, blue<br>
  3. B-day, red</strong></p>
  
  <p>and  <code>foreach</code> <code>$events</code> to avoid non-object call.</p>
  
  <pre><code>foreach($events as $e)
  {
      $name = $e-&gt;getName();
      $color = $e-&gt;getColor();
  }
  </code></pre>
  
  <p>Now I could just return array to twig and for loop them, but can I store them into arrays in controller? </p>
  
  <p><strong>My current code</strong></p>
  
  <pre><code>$events = 
  $this-&gt;getDoctrine()-&gt;getRepository('TestBundle:Events')-&gt;findBy(array('event' =&gt; $eventId));
  
  foreach($events as $e)
  {                   
      $name = $e-&gt;getName();
      $color = $e-&gt;getColor();
  
      $array = array(array("$name", "$color"));
  }
  
  return new JsonResponse($array);
  </code></pre>
  
  <p>With this I get only last array. In this case <strong>B-day, red.</strong> Hopefully someone can help me out with my question. Thanks for time!</p>