title: Adding Elements To An StdClass Array - PHP / Codeigniter
body: <p>I have an array that is an stdClass. The output of that array is as follows :</p>
  
  <pre><code>Array
  (
  [0] =&gt; stdClass Object
      (
          [vendor_id] =&gt; 1
          [user_id] =&gt; 1
          [date_created] =&gt; 2013-06-12 16:48:38
          [date_edited] =&gt; 
          [status] =&gt; active
          [user_firstname] =&gt; Stuart
          [user_surname] =&gt; Blackett
      )
   )
  </code></pre>
  
  <p>What I would like to do is add two variables to this stdClass. They are "total_bookings" and "total_venues";</p>
  
  <p>I currently am looping through the results and then getting a count to create the total. I would like to add those two vars to the end of that stdClass array.</p>
  
  <p>My PHP is as follows :</p>
  
  <pre><code>$vendors = $this-&gt;po_model-&gt;get_all_vendors();
  
          $this-&gt;template-&gt;set('total_vendors', count($vendors));
  
          $count = 0;
  
          foreach($vendors as $vendor)
          {
              $count++;
  
              $total_venues = $this-&gt;po_model-&gt;get_count_venues($vendor-&gt;user_id);
              $total_bookings = $this-&gt;po_model-&gt;get_count_bookings($vendor-&gt;user_id);
  
              $vendors[$count]['total_venues'] = $total_venues;
              $vendors[$count]['total_bookings'] = $total_bookings;
          }
  </code></pre>
  
  <p>However, When I var_dump that my Array looks like this :</p>
  
  <pre><code>Array
  (
      [0] =&gt; stdClass Object
          (
              [vendor_id] =&gt; 1
              [user_id] =&gt; 1
              [date_created] =&gt; 2013-06-12 16:48:38
              [date_edited] =&gt; 
              [status] =&gt; active
              [user_firstname] =&gt; Stuart
              [user_surname] =&gt; Blackett
          )
  
      [1] =&gt; Array
          (
              [total_venues] =&gt; 6
              [total_bookings] =&gt; 14
          )
  
  )
  </code></pre>
  
  <p>So my question is, How do I add total_venues and total_bookings to that stdClass()?</p>
  
  <p>Thanks</p>