我想循环我调用的所有数据,但这只运行一个数据我使用Codeigniter框架
模型:
$this->db->where('group_user', 'upt_perpus')->order_by('idmodul', 'DESC')->get('menu')->result_array();
控制器:
$data = array(
'about' => array(
'sejarah' => 'Sejarah',
'visi_misi' => 'Visi, Misi & Tujuan',
'struktur' => 'Struktur Organisasi'
),
'services' => array(),
'peraturan' => array(
'umum' => 'Umum',
'khusus' => 'Khusus',
'pelayanan_perpus' => 'Pelayanan Perpustakaan'
)
);
$konten = $this->kontens->getPerpus();
foreach ($konten as $key) {
$data['services'] = array(
$key['slug'] => $key['judul']
);
}
return $data;
如果您想在$data['services']
中使用关联数组,则需要为该数组分配一个键。
foreach ($konten as $key) {
$data['services'][$key['slug']] = $key['judul'];
}