Best way to convert Doctrine 2 entity persistent collection to array with Zend Framework 2

Łukasz picture Łukasz · Feb 28, 2014 · Viewed 24.5k times · Source

What is best way (easy) to convert Doctrine 2 entity persistent collection to array with Zend Framework 2? I want convert to array and later output it with JsonView. I can write function which use get_object_var but it is a problem when entity has next entity collection.

Regards.

Answer

Aurelijus Rozenas picture Aurelijus Rozenas · Feb 19, 2015

Not sure about Zend, but in SF2 + Doctrine you can use getValues() method.

$asArray = $persistentCollection->getValues();