如何在foreach中访问这些数组?

时间:2017-05-27 10:15:37

标签: php multidimensional-array codeigniter-3

我在视图中如何在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();

        }

1 个答案:

答案 0 :(得分: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);