Multidimensional array results with joins
<p>I'm joining tables and I'd like to get multidimensional query results based on my joins.</p>

<pre><code># AppBundle:ProductRepository

$this-&gt;createQueryBuilder('pr')
    -&gt;select('pk.id', 'pk.name', 'pr.id', 'pr.label')
    -&gt;join('pr.package', 'pk')
    -&gt;getQuery()-&gt;getResult();
</code></pre>

<p>As you can see <code>Product</code> is linked to a <code>Package</code> (many to one)</p>

<p>Here is the kind of result I'm getting:</p>

<pre><code>array(
    array('id' =&gt; '1', 'name' =&gt; 'package 1', 'id1' =&gt; 1, 'label' =&gt; 'product 1'),
    array('id' =&gt; '1', 'name' =&gt; 'package 1', 'id1' =&gt; 2, 'label' =&gt; 'product 2'),
    array('id' =&gt; '2', 'name' =&gt; 'package 2', 'id1' =&gt; 3, 'label' =&gt; 'product 3'),
)
</code></pre>

<p>Here is what I'd like to get:</p>

<pre><code>array(
    array(
        'id' =&gt; '1',
        'name' =&gt; 'package 1',
        'products' =&gt; array(
            array(
                'id' =&gt; 1,
                'label' =&gt; 'product 1',
            ),
            array(
                'id' =&gt; 2,
                'label' =&gt; 'product 2',
            ),
        ),
    ),
    array(
        'id' =&gt; '2',
        'name' =&gt; 'package 2',
        'products' =&gt; array(
            array(
                'id' =&gt; 3,
                'label' =&gt; 'product 3',
            ),
        ),
    ),
)
</code></pre>

<p>Is there a way to hydrate this kind of multidimensional array with Doctrine 2 ?</p>

<p><em>I mean with Doctrine 2, not with "post prod" php loops</em></p>