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