回答編集履歴
2
chousei
test
CHANGED
@@ -24,3 +24,29 @@
|
|
24
24
|
print "</tr>";
|
25
25
|
}
|
26
26
|
```
|
27
|
+
|
28
|
+
# 配列の個数で自動的に
|
29
|
+
以下例だと$listの行数-1がcolspanの値になると思います。
|
30
|
+
ついでに先頭列がthだったのを忘れていたので処理を入れておきました
|
31
|
+
```PHP
|
32
|
+
<?PHP
|
33
|
+
$list = [
|
34
|
+
['col1'=>1,'col2'=>2,'col3'=>3,'col4'=>4],
|
35
|
+
['col1'=>5,'col2'=>6,'col3'=>7,'col4'=>8],
|
36
|
+
['col1'=>9,'col2'=>10],
|
37
|
+
['col1'=>11,'col2'=>12],
|
38
|
+
['col1'=>13,'col2'=>14],
|
39
|
+
['col1'=>15,'col2'=>16],
|
40
|
+
];
|
41
|
+
|
42
|
+
print "<table border>\n";
|
43
|
+
foreach($list as $key1=>$row){
|
44
|
+
print "<tr>\n";
|
45
|
+
foreach($row as $key2=>$val){
|
46
|
+
$tag=$key2=="col1"?"th":"td";
|
47
|
+
$rowspan=($key1==1 and in_array($key2,["col3","col4"]))?" rowspan=".(count($list)-1):"";
|
48
|
+
print "<{$tag}{$rowspan}>{$val}</{$tag}>\n";
|
49
|
+
}
|
50
|
+
print "</tr>";
|
51
|
+
}
|
52
|
+
```
|
1
調整
test
CHANGED
@@ -1 +1,26 @@
|
|
1
1
|
ご提示のテーブルは行数がたりなくてrowspanがあふれていて不整合です
|
2
|
+
# sample
|
3
|
+
こういうことをしたいのでしょうか?
|
4
|
+
元データの持ち方と、条件次第です
|
5
|
+
```PHP
|
6
|
+
<?PHP
|
7
|
+
$list = [
|
8
|
+
['col1'=>1,'col2'=>2,'col3'=>3,'col4'=>4],
|
9
|
+
['col1'=>5,'col2'=>6,'col3'=>7,'col4'=>8],
|
10
|
+
['col1'=>9,'col2'=>10],
|
11
|
+
['col1'=>11,'col2'=>12],
|
12
|
+
['col1'=>13,'col2'=>14],
|
13
|
+
['col1'=>15,'col2'=>16],
|
14
|
+
//以下略
|
15
|
+
];
|
16
|
+
|
17
|
+
print "<table border>\n";
|
18
|
+
foreach($list as $key1=>$row){
|
19
|
+
print "<tr>\n";
|
20
|
+
foreach($row as $key2=>$val){
|
21
|
+
$rowspan=($key1==1 and in_array($key2,["col3","col4"]))?" rowspan=17":"";
|
22
|
+
print "<td{$rowspan}>{$val}</td>\n";
|
23
|
+
}
|
24
|
+
print "</tr>";
|
25
|
+
}
|
26
|
+
```
|