Php 已将多维数组传递到codeigniter中的视图
我正在尝试使用多维数组创建foreach语句 控制器:Php 已将多维数组传递到codeigniter中的视图,php,codeigniter,multidimensional-array,Php,Codeigniter,Multidimensional Array,我正在尝试使用多维数组创建foreach语句 控制器: function index() { $index1 = 0; $index2 = 0; $index3 = 0; $index4 = 0; $result1 = $this->data->get_test('kdprogram','kdprogram'); foreach($result1 as $row1){ $array_temp[$index1] = $ro
function index()
{
$index1 = 0;
$index2 = 0;
$index3 = 0;
$index4 = 0;
$result1 = $this->data->get_test('kdprogram','kdprogram');
foreach($result1 as $row1){
$array_temp[$index1] = $row1;
$result2 = $this->data->get_test('kdgiat','kdgiat','kdprogram = '.$row1['kdprogram']);
foreach($result2 as $row2){
$array_temp[$index1][$index2] = $row2;
$result3 = $this->data->get_test('kdoutput','kdoutput','kdprogram = '.$row1['kdprogram'].' and kdgiat = '.$row2['kdgiat']);
foreach($result3 as $row3){
$array_temp[$index1][$index2][$index3] = $row3;
$result4 = $this->data->get_test('kdsoutput','kdsoutput','kdprogram = '.$row1['kdprogram'].' and kdgiat = '.$row2['kdgiat'] .' and kdoutput = '.$row3['kdoutput']);
foreach($result4 as $row4){
$array_temp[$index1][$index2][$index3][$index4] = $row4;
$index4++;
}
$index3 ++;
}
$index2 ++;
}
$index1 ++;
}
//print_r($array_temp);
$data['damn'] = $array_temp;
$this->load->view('report/laporan_output', $data);
}
$data包含:
Array
(
[0] => Array
(
[kdprogram] => 06
[0] => Array
(
[kdgiat] => 3400
[0] => Array
(
[kdoutput] => 001
[0] => Array
(
[kdsoutput] => 001
)
[1] => Array
(
[kdsoutput] => 006
)
)
[1] => Array
(
[kdoutput] => 008
[2] => Array
(
[kdsoutput] => 001
)
)
)
)
)
如何回显视图中的每个数组(kdprogram、kdgiat等),尤其是html表?
我做得对吗
谢谢它看起来有点难看,我会使用某种递归函数,但这是你的方法 在控制器中(我假设数组具有数字索引,否则您必须像在代码中那样使用某种计数器) 在视图中
foreach($result as $a )
{
// show a
foreach($a['child'] as $b )
{
// show b
foreach($b['child'] as $c )
{
// show c
foreach($c['child'] as $d )
{
// show d
}
}
}
}
当你处理大量的记录时,所有这些嵌套的前额会变得非常沉重。尽量避免。谢谢你,麦克斯!很抱歉反应太晚:)
foreach($result as $a )
{
// show a
foreach($a['child'] as $b )
{
// show b
foreach($b['child'] as $c )
{
// show c
foreach($c['child'] as $d )
{
// show d
}
}
}
}