我在Code Igniter中创建了表单,我想使用帮助器form_dropdown()
。为了做到这一点我要准备这样的关联数组:关联数组 - 动态创建(CodeIgniter)
$options = array(
'small' => 'Samsung',
'med' => 'Apple',
'large' => 'HTC',
'xlarge' => 'Nokia',
);
但是在该视图中该数据从控制器,其从模型取出当然,传送。
$this->db->select('id');
$query = $this->db->get('ci_table1');
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$data[] = $row;
};
};
$id_data['id'] = $data;
$this->load->view('update_record_view', $id_data);
因此,对的侧面来看我有foreach
-loop:
foreach ($id as $row)
{
// this I want to construct associative array
}
问题是遵循:如何在我的情况下创建关联数组动态?
您没有提供足够的信息来回答这个问题。你的数据来自哪里?查询() - > result_array()? – 2012-08-09 08:08:29
是的,你说得对 - 我已经更新了主题。 – 2012-08-09 08:11:59