title: Warning (2): Invalid argument supplied for foreach()
body: <p>I have the follow array structure and I am successfully looping through the [LoyaltyHistory] part using a for each loop:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [LoyaltyHistory] =&gt; Array
                  (
                      [id] =&gt; 5
                      [user_id] =&gt; 32
                      [points] =&gt; 4
                      [date] =&gt; 2012-02-07
                      [total] =&gt; 146
                  )
  
              [User] =&gt; Array
                  (
                  )
  
          )
  
      [1] =&gt; Array
          (
              [LoyaltyHistory] =&gt; Array
                  (
                      [id] =&gt; 6
                      [user_id] =&gt; 32
                      [points] =&gt; -6
                      [date] =&gt; 2012-02-07
                      [total] =&gt; 140
                  )
  
              [User] =&gt; Array
                  (
                  )
  
          )
  
      [2] =&gt; Array
          (
              [LoyaltyHistory] =&gt; Array
                  (
                      [id] =&gt; 7
                      [user_id] =&gt; 32
                      [points] =&gt; -5
                      [date] =&gt; 2012-02-07
                      [total] =&gt; 135
                  )
  
              [User] =&gt; Array
                  (
                  )
  
          )
  
      [3] =&gt; Array
          (
              [LoyaltyHistory] =&gt; Array
                  (
                      [id] =&gt; 8
                      [user_id] =&gt; 32
                      [points] =&gt; 15
                      [date] =&gt; 2012-02-07
                      [total] =&gt; 150
                  )
  
              [User] =&gt; Array
                  (
                  )
  
          )
  
      [4] =&gt; Array
          (
              [LoyaltyHistory] =&gt; Array
                  (
                      [id] =&gt; 9
                      [user_id] =&gt; 32
                      [points] =&gt; 5
                      [date] =&gt; 2012-02-10
                      [total] =&gt; 155
                  )
  
              [User] =&gt; Array
                  (
                  )
  
          )
  
      [5] =&gt; Array
          (
              [LoyaltyHistory] =&gt; Array
                  (
                      [id] =&gt; 10
                      [user_id] =&gt; 32
                      [points] =&gt; 155
                      [date] =&gt; 2012-03-04
                      [total] =&gt; 305
                  )
  
              [User] =&gt; Array
                  (
                  )
  
          )
  
      [6] =&gt; Array
          (
              [LoyaltyHistory] =&gt; Array
                  (
                      [id] =&gt; 11
                      [user_id] =&gt; 32
                      [points] =&gt; -5
                      [date] =&gt; 2012-03-04
                      [total] =&gt; 300
                  )
  
              [User] =&gt; Array
                  (
                  )
  
          )
  
      [7] =&gt; Array
          (
              [LoyaltyHistory] =&gt; Array
                  (
                      [id] =&gt; 12
                      [user_id] =&gt; 32
                      [points] =&gt; 5
                      [date] =&gt; 2012-03-05
                      [total] =&gt; 305
                  )
  
              [User] =&gt; Array
                  (
                  )
  
          )
  
  )
  </code></pre>
  
  <p>the for each loop is structured as follows:</p>
  
  <pre><code>&lt;?php foreach ($history as $hist) 
      {
         if($hist['LoyaltyHistory']['points'] &gt; 0) $hist['LoyaltyHistory']['points'] = '+'.$hist['LoyaltyHistory']['points'];?&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;&lt;?php echo $hist['LoyaltyHistory']['date']; ?&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;?php echo $hist['LoyaltyHistory']['points']; ?&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;?php echo $hist['LoyaltyHistory']['total']; ?&gt;&lt;/td&gt;
                                  &lt;/tr&gt;
                      &lt;?php   } ?&gt;
  </code></pre>
  
  <p>The for each loop is outputing the correct elements from the array but it is causing the following warning: <code>'Warning (2): Invalid argument supplied for foreach()'</code> and I can't figure out why.</p>