回答編集履歴

2

chuosei

2020/11/14 14:49

投稿

yambejp
yambejp

スコア116724

test CHANGED
@@ -104,6 +104,8 @@
104
104
 
105
105
  ];
106
106
 
107
+ $per=4;//ホントは12とかになる?
108
+
107
109
  $new=array_map(function($x) use($datas){
108
110
 
109
111
  return array_map(function($y) use($x){
@@ -116,8 +118,12 @@
116
118
 
117
119
  },array_keys($datas[0]));
118
120
 
119
- },array_chunk($datas,4));
121
+ },array_chunk($datas,$per));
120
122
 
121
123
  print_r($new);
122
124
 
123
125
  ```
126
+
127
+
128
+
129
+ ※一部補足をいれました補足

1

sample

2020/11/14 14:49

投稿

yambejp
yambejp

スコア116724

test CHANGED
@@ -1 +1,123 @@
1
1
  2018と2019を別の配列に切り分けて、縦軸と横軸を入れ替えてから処理すると良いでしょう
2
+
3
+ # sample
4
+
5
+ ```PHP
6
+
7
+ $datas=[
8
+
9
+ [
10
+
11
+ "m"=>"2018-01",
12
+
13
+ "am"=>"10",
14
+
15
+ "pm"=>"20",
16
+
17
+ "sum"=>"30",
18
+
19
+ ],
20
+
21
+ [
22
+
23
+ "m"=>"2018-02",
24
+
25
+ "am"=>"11",
26
+
27
+ "pm"=>"21",
28
+
29
+ "sum"=>"32",
30
+
31
+ ],
32
+
33
+ [
34
+
35
+ "m"=>"2018-11",
36
+
37
+ "am"=>"15",
38
+
39
+ "pm"=>"16",
40
+
41
+ "sum"=>"31",
42
+
43
+ ],
44
+
45
+ [
46
+
47
+ "m"=>"2018-12",
48
+
49
+ "am"=>"18",
50
+
51
+ "pm"=>"20",
52
+
53
+ "sum"=>"38",
54
+
55
+ ],
56
+
57
+ [
58
+
59
+ "m"=>"2019-01",
60
+
61
+ "am"=>"12",
62
+
63
+ "pm"=>"15",
64
+
65
+ "sum"=>"27",
66
+
67
+ ],
68
+
69
+ [
70
+
71
+ "m"=>"2019-02",
72
+
73
+ "am"=>"14",
74
+
75
+ "pm"=>"15",
76
+
77
+ "sum"=>"29",
78
+
79
+ ],
80
+
81
+ [
82
+
83
+ "m"=>"2019-11",
84
+
85
+ "am"=>"10",
86
+
87
+ "pm"=>"14",
88
+
89
+ "sum"=>"24",
90
+
91
+ ],
92
+
93
+ [
94
+
95
+ "m"=>"2019-12",
96
+
97
+ "am"=>"18",
98
+
99
+ "pm"=>"15",
100
+
101
+ "sum"=>"23",
102
+
103
+ ],
104
+
105
+ ];
106
+
107
+ $new=array_map(function($x) use($datas){
108
+
109
+ return array_map(function($y) use($x){
110
+
111
+ return array_merge([$y],array_map(function($z) use($y){
112
+
113
+ return $z[$y];
114
+
115
+ },$x));
116
+
117
+ },array_keys($datas[0]));
118
+
119
+ },array_chunk($datas,4));
120
+
121
+ print_r($new);
122
+
123
+ ```