回答編集履歴

2

調整

2022/06/02 07:32

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -1,7 +1,5 @@
1
1
  こんな感じで変換してみてください
2
2
  ```PHP
3
- <?PHP
4
-
5
3
  $data=[
6
4
  ["color"=>"red", "things"=>"りんご","place"=>"青森"],
7
5
  ["color"=>"red", "things"=>"信号" ,"place"=>"東京"],
@@ -23,6 +21,7 @@
23
21
  },[]);
24
22
  print_r($result);
25
23
  print "<table border>\n";
24
+ print "<thead>\n<tr><th>color</th><th>things</th><th>place</th></tr>\n</thead>\n";
26
25
  print "<tbody>\n";
27
26
  foreach($result as $color=>$vals){
28
27
  print "<tr>";
@@ -38,5 +37,4 @@
38
37
  }
39
38
  print "</tbody>\n";
40
39
  print "</table>\n";
41
-
42
40
  ```

1

調整

2022/06/02 07:29

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -1,5 +1,7 @@
1
1
  こんな感じで変換してみてください
2
2
  ```PHP
3
+ <?PHP
4
+
3
5
  $data=[
4
6
  ["color"=>"red", "things"=>"りんご","place"=>"青森"],
5
7
  ["color"=>"red", "things"=>"信号" ,"place"=>"東京"],
@@ -14,10 +16,27 @@
14
16
  $x[$y]=array_map(function($x){
15
17
  unset($x["color"]);
16
18
  return $x;
17
- },array_filter($data,function($x) use($y){
19
+ },array_values(array_filter($data,function($x) use($y){
18
20
  return $x["color"]==$y;
19
- }));
21
+ })));
20
22
  return $x;
21
23
  },[]);
22
24
  print_r($result);
25
+ print "<table border>\n";
26
+ print "<tbody>\n";
27
+ foreach($result as $color=>$vals){
28
+ print "<tr>";
29
+ print "<td rowspan=\"".count($vals)."\">$color</td>";
30
+ foreach($vals as $key=>$val){
31
+ if($key>0){
32
+ print "</tr>\n<tr>";
33
+ }
34
+ print "<td>${val["things"]}</td>";
35
+ print "<td>${val["place"]}</td>";
36
+ }
37
+ print "</tr>\n";
38
+ }
39
+ print "</tbody>\n";
40
+ print "</table>\n";
41
+
23
42
  ```