title: create a multidimensional array in codeigniter controller
body: <p>I'm having a controller to get users from DB and display every user in a table row</p>
  
  <pre><code>Controller: [update] //only first page displays data correctly but pager +1 using 
  pagination displays user data only not getting orders as first page
  when I print_r($orders) in all pages I get correct orders but in the table the inner 
  foreach doesn't work
  
  public function index($page_id = 1)
  {
      $perPage = 25;
      $offset = ($page_id - 1) * $perPage;
  
      if ($offset &lt; 0) {
          $offset = $perPage;
      }
      $lang_id = $this-&gt;data['active_language']-&gt;id;
      $config['base_url'] = base_url() . "reports/myController/index/";
      $config['per_page'] = $perPage;
      $config['first_link'] = FALSE;
      $config['last_link'] = FALSE;
      $config['uri_segment'] = 4;
      $config['use_page_numbers'] = TRUE;
      $config['first_link'] = lang('first_page');
      $config['last_link'] = lang('last_page');
      $config['first_tag_open'] = '&lt;li&gt;';
      $config['first_tag_close'] = '&lt;/li&gt;';
      $config['last_tag_open'] = '&lt;li&gt;';
      $config['last_tag_close'] = '&lt;/li&gt;';
      $config['next_tag_open'] = '&lt;li&gt;';
      $config['next_tag_close'] = '&lt;/li&gt;';
      $config['prev_tag_open'] = '&lt;li&gt;';
      $config['prev_tag_close'] = '&lt;/li&gt;';
      $config['num_tag_open'] = '&lt;li&gt;';
      $config['num_tag_close'] = '&lt;/li&gt;';
      $config['cur_tag_open'] = '&lt;li&gt;&lt;strong&gt;';
      $config['cur_tag_close'] = '&lt;/strong&gt;&lt;/li&gt;';
  
      $config['display_pages'] = TRUE;
  
      $orders_serials_ids = $this-&gt;myModel-&gt;get_orders_serials_ids();
  
      $config['total_rows'] = $this-&gt;myModel-&gt;count_orders();
  
      $this-&gt;pagination-&gt;initialize($config);
  
      $users = $this-&gt;myModel-&gt;users_merchants($perPage, $offset);
      $this-&gt;data['users'] = $users;
  
      $user_orders = array();
      foreach ($users as $user){
          $user_orders[$user-&gt;user_id] = $this-&gt;myModel-&gt;get_orders($user-&gt;user_id);
      }
  
  View:
  &lt;table&gt;
      &lt;tr&gt;
        &lt;th&gt;
          &lt;?php echo 'user';?&gt;
        &lt;/th&gt;
        &lt;th&gt;
          &lt;?php echo 'email';?&gt;
        &lt;/th&gt;            
        &lt;th&gt;
          &lt;?php echo 'device id';?&gt;
        &lt;/th&gt;
      &lt;/tr&gt;
      &lt;?php
      foreach($users as $val){
      ?&gt;
      &lt;tr&gt;
        &lt;td&gt;
          &lt;?=$val-&gt;user_id?&gt;
        &lt;/td&gt;
        &lt;td&gt;
          &lt;?php echo $val-&gt;email;?&gt;
         &lt;/td&gt;
         &lt;td&gt;
          &lt;?php echo $val-&gt;device_id;?&gt;
         &lt;/td&gt;
      &lt;/tr&gt;
      &lt;?php
      $order = array(); //empty the variable before each loop
      foreach($orders[$user-&gt;user_id] as $order){
          echo '&lt;tr&gt;&lt;td colspan="4"&gt;'. date('Y-m',$order-&gt;unix_time).
  ' -&gt; '.round($order-&gt;amount2,2).'&lt;/td&gt;&lt;/tr&gt;';                   
      }
  }
  ?&gt;
  &lt;/table&gt;
  &lt;ul class="pagination"&gt;&lt;?php if($pagination) echo $pagination;?&gt;&lt;/ul&gt;
  
  user id    user name        user email
  1          Mike             mike@yahoo.com
  order:10   order total:50   order date: 2016-09-12
  order:12   order total:100  order date: 2016-09-14
  2          Tom              Tom@live.com
  order:15   order total:80   order date: 2016-09-13
  order:16   order total:120  order date: 2016-09-14
  order:17   order total:140  order date: 2016-10-10      
  </code></pre>
  
  <p>This works in the first page only but when I navigate to second page the controller url changes to index/2 r any other page number I get users rows without data orders though if I print_r orders above the table I get correct orders</p>