Code Igniterにフォームがあり、ヘルパーを使用したいと思いますform_dropdown()
。それを行うには、次のような連想配列を準備する必要があります。
$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
}
質問は次のとおりです:私の場合、連想配列を動的に作成する方法は?