9

I retrieve all objects for an entity like this:

$allQuestions = $em->getRepository('AppMyBundle:Question')
    ->findBy(array('isActive' => true, 'isDeleted' => false));

I get an array of objects into $allQuestions. Is there a possibility to get an ArrayCollection instead of an array?

A.L
  • 10,259
  • 10
  • 67
  • 98
smartcoderx
  • 1,021
  • 2
  • 14
  • 32
  • You can convert it to an Arraycollection right ? – robin Apr 22 '15 at 07:09
  • `ArrayCollection` it is an array of objects, you alredy getting the `ArrayCollection`, check the http://stackoverflow.com/questions/29180651/arraycollection-in-symfony/29181036#29181036 response for more details about what it is an array collection – Alexandru Olaru Apr 22 '15 at 08:37

1 Answers1

18

You could just do

$collection = new ArrayCollection($allQuestions);

To convert the array to an ArrayCollection.

vdwijngaert
  • 1,515
  • 11
  • 24