title: Array loses values when in foreach
body: <p>This has me stumped. I can print_r the array called <code>$item_pages</code> and it outputs all of the keys and values correctly. However, once that array is used within the foreach, it seems to become empty. This is the array when I print_r outside of the foreach:</p>
  
  <pre><code>Array ( [0] =&gt; 1 [1] =&gt; 6 [2] =&gt; 12 [3] =&gt; 15 [4] =&gt; 16 [5] =&gt; 17 [6] =&gt; 18 [7] =&gt; 19 [8] =&gt; 78 [9] =&gt; 79 [10] =&gt; 87 [11] =&gt; 90 [12] =&gt; 94 [13] =&gt; 95 [14] =&gt; 98 [15] =&gt; 99 [16] =&gt; 102 [17] =&gt; 103 [18] =&gt; 105 [19] =&gt; 107 [20] =&gt; 108 [21] =&gt; 110 [22] =&gt; 111 [23] =&gt; 112 [24] =&gt; 113 [25] =&gt; 114 [26] =&gt; 119 [27] =&gt; 120 [28] =&gt; 121 [29] =&gt; 125 [30] =&gt; 126 [31] =&gt; 134 [32] =&gt; 135 [33] =&gt; 136 [34] =&gt; 138 [35] =&gt; 142 [36] =&gt; 186 [37] =&gt; 193 [38] =&gt; 197 [39] =&gt; 198 [40] =&gt; 199 [41] =&gt; 206 [42] =&gt; 327 [43] =&gt; 452 [44] =&gt; 470 [45] =&gt; 487 [46] =&gt; 601 [47] =&gt; 614 [48] =&gt; 630 [49] =&gt; 684 [50] =&gt; 726 [51] =&gt; 727 [52] =&gt; 789 [53] =&gt; 871 )
  </code></pre>
  
  <p>Here's the controller:</p>
  
  <pre><code>    public function view_item_pages() {
  
      if ($this-&gt;input-&gt;is_ajax_request()) {
  
        $item_id = $this-&gt;input-&gt;post('item_id');
        $this-&gt;data['item_id'] = $item_id;
        $this-&gt;data['pages'] = $this-&gt;affiliate_model-&gt;get_all_affiliates();
        $this-&gt;data['item_pages'] = $this-&gt;item_model-&gt;get_item_pages($item_id);
  
        $this-&gt;load-&gt;view('/admin/item/pages', $this-&gt;data);
  
      }
  
    }
  </code></pre>
  
  <p>Here's the view:</p>
  
  <pre><code>&lt;fieldset&gt;
      &lt;table id="all-pages" class="table table-striped table-bordered"&gt;
          &lt;thead&gt;
            &lt;tr&gt;
              &lt;th&gt;&lt;input type="checkbox" class="checkbox" id="select_all"&gt;&lt;/th&gt;
              &lt;th&gt;ID&lt;/th&gt;
              &lt;th&gt;Name&lt;/th&gt;
            &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
  
          &lt;?php foreach ($pages as $page): 
  
              $checked = FALSE;
  
              if (!empty($item_pages)) {
                  if (in_array($page['aff_id'], $item_pages)) {
                      $checked = TRUE;
                  }
              }
          ?&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;?php echo form_checkbox('page', $page['aff_id'], $checked); ?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $page['aff_id']; ?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $page['name']; ?&gt;&lt;/td&gt;
                &lt;/tr&gt;
  
          &lt;?php endforeach; ?&gt;
  
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/fieldset&gt;
  </code></pre>
  
  <p>So if I do the following, the array works:</p>
  
  <pre><code>    &lt;?php print_r($item_pages); ?&gt;
  
      &lt;?php foreach ($pages as $page):
  
          $checked = FALSE;
  
          if (!empty($item_pages)) {
              if (in_array($page['aff_id'], $item_pages)) {
                  $checked = TRUE;
              }
          }
      ?&gt;
  </code></pre>
  
  <p>If I do this, it doesn't return anything, it's like doing <code>echo '';</code>:</p>
  
  <pre><code>   &lt;?php foreach ($pages as $page):
  
          print_r($item_pages);
  
          $checked = FALSE;
  
          if (!empty($item_pages)) {
              if (in_array($page['aff_id'], $item_pages)) {
                  $checked = TRUE;
              }
          }
      ?&gt;
  </code></pre>