How to Turn a Doctrine_Collection of Objects into a PHP Array

Hint: toArray() is probably not what you’re looking for.

->toArray()

Most programmers would probably assume that calling toArray() on the collection would simply place all the objects into an array. While toArray() does do that, it also converts the objects themselves into associative arrays, which is likely not what you want.

->getData()

Not exactly the most intuitive name, getData() actually takes all the objects in the Doctrine Collection object and places them into an array – without altering the objects themselves.

This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to How to Turn a Doctrine_Collection of Objects into a PHP Array

  1. martin says:

    getDate() was exactly what I was looking for, but it has really ambiguous name. Thanks for sharing!

  2. pariss says:

    thanks a lot!
    that’s what i really looked for!:)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>