title: How to separate array from nested arrays with MongoDB and PHP aggregate?
body: <p>I would like to get the distinct <code>code_y</code> values, and I use below code, the output is equal to <code>select distinct code_y from table_x</code>,</p>
  <pre><code>$res = $db_x-&gt;command (
          array(
              &quot;aggregate&quot; =&gt; &quot;table_x&quot;,
              &quot;pipeline&quot; =&gt;
                  array(
                      array( '$group' =&gt; array( &quot;_id&quot; =&gt; ['id' =&gt;'$code_y', 'name' =&gt; '$code_x', 'color' =&gt; '$color']))),
              &quot;cursor&quot; =&gt; ['batchSize' =&gt; 200]
          )
  );
  </code></pre>
  <p>I got results as below, I don't need <code>[_id] =&gt; Array</code>, just id, name and color, How to separate array from nested arrays with MongoDB and PHP aggregate? Or how to put <code>[_id] =&gt; Array</code> together with <code>id, name and color</code>? as in my front-end htmls pages, I got <code>[object] [Object]</code> because of those nested arrays.</p>
  <hr />
  <pre><code>   [0] =&gt; Array
          (
              [_id] =&gt; Array
                  (
                      [id] =&gt; a1
                      [name] =&gt; bbb
                      [color] =&gt; blue
                  )
  
          )
  
      [1] =&gt; Array
          (
              [_id] =&gt; Array
                  (
                      [id] =&gt; a2
                      [name] =&gt; aaa
                      [color] =&gt; blue
                  )
  
          )
  
      [2] =&gt; Array
          (
              [_id] =&gt; Array
                  (
                      [id] =&gt; a3
                      [name] =&gt; abc
                      [color] =&gt;red
                  )
  
          )
  </code></pre>
  <hr />
  <p>What I want is as below:</p>
  <pre><code>[0] =&gt; Array
      (
         [id] =&gt; a1
         [name] =&gt; bbb
         [color] =&gt; blue
      )
  
  [1] =&gt; Array
      (
         [id] =&gt; a2
         [name] =&gt; aaa
         [color] =&gt; blue
  
  
      )
  
  [2] =&gt; Array
      (
        [id] =&gt; a3
        [name] =&gt; abc
        [color] =&gt;red
      )
  </code></pre>