I'm trying to get a multi-dimensional array from an Entity.
Symfony Serializer can already convert to XML, JSON, YAML etc. but not to an array.
I need to convert because I want have a clean var_dump
. I now have entity with few connections and is totally unreadable.
How can I achieve this?
Apparently, it is possible to cast objects to arrays like following:
This will produce something like:
If you have got private and protected attributes see this link : https://ocramius.github.io/blog/fast-php-object-to-array-conversion/
Get entity in array format from repository query
In your EntityRepository you can select your entity and specify you want an array with
getArrayResult()
method.For more informations see Doctrine query result formats documentation.
If all that doesn't fit you should go see the PHP documentation about ArrayAccess interface.
It retrieves the attributes this way :
echo $entity['Attribute'];