【问题标题】:How can i access these arrays in foreach?如何在 foreach 中访问这些数组?
【发布时间】:2017-05-27 10:15:36
【问题描述】:
在我看来,我如何在 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();
}
【问题讨论】:
标签:
php
multidimensional-array
codeigniter-3
【解决方案1】:
在你的控制器中
$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);