title: PHP LaravelMerge data to single array
body: <p>I am trying to get data from DB into a single array</p>
  
  <p>This what I have tried: </p>
  
  <pre><code>foreach ($userid as &amp;$user){
  
          foreach ($first_week_of_month as $day){
          //Get Total Number of Personal Leads By User ID &amp; Requested week Through Each Day
          $personalleads = \DB::table('leads') 
          -&gt;where('owned_by_id', $id) // User ID
          -&gt;where('lead_source_id', 7) // 7 = Personal Lead
          -&gt;get(); // Get All Data
          $user-&gt;pleads = $personalleads-&gt;count();
  
          //Get Total Number of leads Created by Managers By User ID &amp; Requested week Through Each Day
          $managerleads = \DB::table('leads') 
          -&gt;where('owned_by_id', $id) // User ID
          -&gt;where('lead_source_id', 3) // 3 = Manager Lead
          -&gt;get(); // Get All Data
          $user-&gt;mleads = $managerleads-&gt;count();
  
           //Get Total Number of leads Created by Admins By User ID &amp; Requested week Through Each Day
          $adminleads = \DB::table('leads') 
          -&gt;where('owned_by_id', $id) // User ID
          -&gt;where('lead_source_id', 4) // 4 = Admin Lead
          -&gt;get(); // Get All Data
          $user-&gt;aleads = $adminleads-&gt;count();
          echo ($userid);
          }
      }
  </code></pre>
  
  <p><strong>What I want:</strong></p>
  
  <pre><code>[  
     {  "userid":1, "pleads":2, "mleads":1, "aleads":1   },
     {  "userid":1, "pleads":0, "mleads":0, "aleads":0   },
     {  "userid":1, "pleads":0, "mleads":0, "aleads":0   },
     {  "userid":1, "pleads":1, "mleads":0, "aleads":0   },
     {  "userid":1, "pleads":1, "mleads":0, "aleads":0   },
     {  "userid":1, "pleads":1, "mleads":0, "aleads":0   },
     {  "userid":1, "pleads":0, "mleads":0, "aleads":0   }
  ]
  </code></pre>
  
  <p><strong>What I get:</strong></p>
  
  <pre><code>[ {  "userid":1, "pleads":2, "mleads":1, "aleads":1   } ]
  [ {  "userid":1, "pleads":0, "mleads":0, "aleads":0   } ]
  [ {  "userid":1, "pleads":0, "mleads":0, "aleads":0   } ]
  [ {  "userid":1, "pleads":1, "mleads":0, "aleads":0   } ]
  [ {  "userid":1, "pleads":1, "mleads":0, "aleads":0   } ]
  [ {  "userid":1, "pleads":1, "mleads":0, "aleads":0   } ]
  [ {  "userid":1, "pleads":0, "mleads":0, "aleads":0   } ]
  []
  </code></pre>
  
  <p><code>print_r</code> of <strong>what I get:</strong></p>
  
  <pre><code>( [items:protected] =&gt; Array ([0]=&gt; stdClass Object ([userid]=&gt; 1[pleads]=&gt; 2[mleads]=&gt; 1[aleads]=&gt; 1 )) ) 
  ( [items:protected] =&gt; Array ([0]=&gt; stdClass Object ([userid]=&gt; 1[pleads]=&gt; 0[mleads]=&gt; 0[aleads]=&gt; 0 )) ) 
  ( [items:protected] =&gt; Array ([0]=&gt; stdClass Object ([userid]=&gt; 1[pleads]=&gt; 0[mleads]=&gt; 0[aleads]=&gt; 0 )) ) 
  ( [items:protected] =&gt; Array ([0]=&gt; stdClass Object ([userid]=&gt; 1[pleads]=&gt; 1[mleads]=&gt; 0[aleads]=&gt; 0 )) ) 
  ( [items:protected] =&gt; Array ([0]=&gt; stdClass Object ([userid]=&gt; 1[pleads]=&gt; 1[mleads]=&gt; 0[aleads]=&gt; 0 )) ) 
  ( [items:protected] =&gt; Array ([0]=&gt; stdClass Object ([userid]=&gt; 1[pleads]=&gt; 1[mleads]=&gt; 0[aleads]=&gt; 0 )) ) 
  ( [items:protected] =&gt; Array ([0]=&gt; stdClass Object ([userid]=&gt; 1[pleads]=&gt; 0[mleads]=&gt; 0[aleads]=&gt; 0 )) )
  </code></pre>