PHP foreach只获取一条数据

PHP Foreach only get one data

我想循环我调用的所有数据,但只运行一个数据 我使用 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'];
  }