如何使用此数组创建表(rowspan和colsopan)

时间:2019-04-30 16:58:40

标签: php html laravel

我有一个像这样的数组

$json = [
            ['No.',"Nama","Luas","D1",null,"D2","DL",null,null],
            [null,null,null,"val1","val2","zal1","yal1",'yal2','yal3'],
        ];

我尝试过的

foreach($firstHeader as $index => $row) {
                if($firstHeader[$index] === null) {
                    if($firstHeader[$index - 1] != null) {
                        \Log::info([$firstHeader[$index - 1], $counter]);
                    }
                    $counter++;
                    $html .= '<th colspan="'.($counter + 1).'">'. $firstHeader[$index - 1] . '</th>';
                } else {
                    $counter = 0;
                    if($secondHeader[$index] === null && $row !== null) {
                        $html .= '<th rowspan="2">'. $firstHeader[$index] . '</th>';
                    }

                    if($firstHeader[$index] != null) {
                        \Log::info([$firstHeader[$index], $counter]);
                    }
                }

            }

我的预期结果是

https://ibb.co/R7P9Vrm

enter image description here

谢谢

0 个答案:

没有答案