迭代数组本身时,将数组当前值发送到加载模型


Send the array current value to load model when iterating the array itself

我想将每个值存储在数组中,以便在迭代数组本身时加载视图。我一直在使用for来实现它,如以下代码:

$seat = (0 => 'a', 1 => 'b', 2 => 'c', 3=> 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k');
$number = 10;
for ($i=0; $i <= $number; $i++) { 
    $this->data['chunked'] = $seat[$i];
    $this->load->view('chunked', $this->data);
}

如何使用 foreach 应用同样的事情,在迭代数组$seat本身时发送数组的当前值?

 foreach ($seat as $key => $value) {
    $this->data['chunked'] = //how to set the current array value being iterated
    $this->load->view('chunked', $this->data);
 }

关键是,我想根据我拥有的数组键数量使用 <div> 生成一些列$seat。所以在这种情况下,我有 11 个从 0 到 10 的键。我希望在迭代数组的同时生成列。最后我将有 11 <div>

foreach ($seat as $key => $value) {
 $this->data['chunked'] = $seat[$key]; //how to set the current array value being iterated
 $this->load->view('chunked', $this->data);
}

要实现完全相同的效果,您可以添加

$seat[$key];