2017-05-27 46 views
-4

我如何在我的視圖中訪問foreach?我如何在foreach中訪問這些數組?

foreach($data as $key => $row){ 
      $col[$row['user_id']][$row['loan_id']] = $this->db->where('loan_user_id', $row['user_id'])->where('loan_id', $row['coll_loan_id'])->get('loans')->result_array(); 
      $col[$row['user_id']][$row['loan_id']][$row['coll_id']] = $this->db->where('coll_loan_id', $row['loan_id'])->where('coll_user_id', $row['user_id'])->get('collectables')->result_array(); 

     } 
+0

哪裏數組你迭代 – Akintunde007

回答

0

在控制器

$col = array(); 
foreach($data as $key => $row){ 
    // Simplified the where condition by using array in where object 
    $user_id = $row['user_id']; 
    $load_id = $row['loan_id']; 
    $col[$user_id][$load_id] = $this->db->where(array('loan_user_id' => $user_id,'loan_id' => $row['coll_loan_id']))->get('loans')->result_array(); 
    $col[$user_id][$load_id][$row['coll_id']] = $this->db->where(array('coll_loan_id' => $row['loan_id'], 'coll_user_id' => $row['user_id']))->get('collectables')->result_array(); 

} 
$this->load->view('view_name', array('view_data' => $col)); 
鑑於文件

// Loop here 
echo '<pre>';print_r($view_data);