title: Multiple foreach to process nested arrays -- PHP CodeIgniter
body: <p>I would first like to thank you for taking the time to look at my question--I am quite novice at PHP/CodeIgniter programming, however, I enjoy it very much.</p>
  
  <p>What I am trying to do:</p>
  
  <p>1) Retrieve each CompanyId associated with the company when the user is logged in. I achieve this by passing the $CompanyId (in my controller) from the session as a parameter to a query in my model. I have this working well as such:</p>
  
  <pre><code> // Assign query result to array  to be used in view
      $data['campaigns'] = $this-&gt;model_record-&gt;retrieve_campaign($CompanyId);
  </code></pre>
  
  <p>2) The return value is an array nested as such:</p>
  
  <pre><code>Array ( 
  [campaigns] =&gt; Array ( 
      [0] =&gt; Array ( 
          [CampaignId] =&gt; 1 
          [DID] =&gt; 2394434444 
          [FWDDID] =&gt; 3214822821 
          [ProductId] =&gt; 1 
          [CampaignName] =&gt; Fort Myers Bus #1 
          [ProductName] =&gt; CallTrack - Sharktek 
          [Active] =&gt; 1 
          [CompanyId] =&gt; 1 ) 
      )
  </code></pre>
  
  <p>3) Once this is processed, I am trying to create a for each loop that queries each CampaignId through another query in my model. Due to the MVC pattern I am implementing, I have to pass the results of this query to my $data array to send to the view. </p>
  
  <pre><code>foreach($data['campaigns'] as $campaign) {
      $ids[] = $campaign['CampaignId'];
  }
  
  foreach ($ids as $row) {
      $data['ids'] = $this-&gt;model_record-&gt;week_data(0,$row, $StartDate);
  }
  </code></pre>
  
  <p>4) I am then trying to test view all the results of my queries in my view, however, I am only receiving one value, but when I echo the results of the foreach of the CampaignIds, it they all show up. Does anyone have any suggestions?</p>
  
  <pre><code>&lt;?php 
  foreach($ids as $row):
  echo $ids['MyCount'];
  endforeach
   ?&gt;
  </code></pre>
  
  <p>5 Extra) I have not begun to approach this yet, but once I get this working, I would like to run the query week_data 7 times as it is returning the data for each day of the week. My assumption is that I would place a for loop until it hits 7, is this correct?</p>
  
  <p>Thank you again, for attempting to help me--I greatly appreciate the work many of you put into this community.</p>