多 Foreach 循环 Codeigniter

Multiple Foreach Loop Codeigniter

我想在不同的部分显示数据,但是当我运行时出错。

控制器

class Dfkamar extends CI_Controller {
public function index() {
    $data['tamu'] = $this ->m_tamu->daftar_kamar()->result();
        $this->load->view('templates/header');
        $this->load->view('templates/sidebar');
        $this->load->view('dfkamar', $data);
        $this->load->view('templates/footer');
}

查看

    <?php
      foreach ($tamu as $tamu) : 
    ?>

        <button type="button" class="btn btn-success"><?php echo $tamu->gateA ?></button>
      </div>  
      <?php endforeach;?>

    <?php
        foreach ($tamu as $tamu1) : 
      ?>

        <button type="button" class="btn btn-success"><?php echo $tamu1->gateB ?></button>
      </div>  
      <?php endforeach;?>

$tamu 数组变量在第一个 foreach 中被替换 $tamu 字符串所以不要那样做

工作代码如下:

$tamu = ['gateA'=>'test-A','gateB'=>'sdfs'];

      foreach ($tamu as $tamu_item) : 
        echo $tamu_item->gateA;
     endforeach;
     
     var_dump($tamu);

    foreach ($tamu as $tamu1) : 
        echo $tamu1->gateB;
     endforeach;