質問編集履歴

1

コメントを受けて、モックを追加しました。

2020/10/07 10:04

投稿

machinokoziya
machinokoziya

スコア11

test CHANGED
File without changes
test CHANGED
@@ -8,198 +8,264 @@
8
8
 
9
9
 
10
10
 
11
- ```ここに言語を入力
12
-
13
- App\School Object
14
-
15
- (
16
-
17
- [original:protected] => Array
18
-
19
- (
20
-
21
- [school_name] => 大阪
22
-
23
- [school_colspan] => 3
24
-
25
- )
26
-
27
- )
28
-
29
- ```
30
-
31
- のように先頭のデータに重複件数を加えて
32
-
33
- Viewで[school_colspan]のあり/なしによってtdを出し分け、
34
-
35
- ある場合はcolspanに件数を出力しようと思っています。
36
-
37
-
38
-
39
- そのために下記データに重複件数を加える書き方を
40
-
41
- ご存知の方いましたら教えていただけますいただければ幸いです。
42
-
43
-
44
-
45
- ### 参考データ
46
-
47
-
48
-
49
- ```
50
-
51
- App\School Object
52
-
53
- (
54
-
55
- [attributes:protected] => Array
56
-
57
- (
58
-
59
- [school_name] => 大阪
60
-
61
- )
62
-
63
- [original:protected] => Array
64
-
65
- (
66
-
67
- [school_name] => 大阪
68
-
69
- )
70
-
71
- )
72
-
73
- App\School Object
74
-
75
- (
76
-
77
- [attributes:protected] => Array
78
-
79
- (
80
-
81
- [school_name] => 大阪
82
-
83
- )
84
-
85
- [original:protected] => Array
86
-
87
- (
88
-
89
- [school_name] => 大阪
90
-
91
- )
92
-
93
- )
94
-
95
- App\School Object
96
-
97
- (
98
-
99
- [attributes:protected] => Array
100
-
101
- (
102
-
103
- [school_name] => 大阪
104
-
105
- )
106
-
107
- [original:protected] => Array
108
-
109
- (
110
-
111
- [school_name] => 大阪
112
-
113
- )
114
-
115
- )
116
-
117
- App\School Object
118
-
119
- (
120
-
121
- [attributes:protected] => Array
122
-
123
- (
124
-
125
- [school_name] => 福岡
126
-
127
- )
128
-
129
- [original:protected] => Array
130
-
131
- (
132
-
133
- [school_name] => 福岡
134
-
135
- )
136
-
137
- )
138
-
139
- App\School Object
140
-
141
- (
142
-
143
- [attributes:protected] => Array
144
-
145
- (
146
-
147
- [school_name] => 長崎
148
-
149
- )
150
-
151
- [original:protected] => Array
152
-
153
- (
154
-
155
- [school_name] => 長崎
156
-
157
- )
158
-
159
- )
160
-
161
- App\School Object
162
-
163
- (
164
-
165
- [attributes:protected] => Array
166
-
167
- (
168
-
169
- [school_name] => 沖縄
170
-
171
- )
172
-
173
- [original:protected] => Array
174
-
175
- (
176
-
177
- [school_name] => 沖縄
178
-
179
- )
180
-
181
- )
182
-
183
- App\School Object
184
-
185
- (
186
-
187
- [attributes:protected] => Array
188
-
189
- (
190
-
191
- [school_name] => 沖縄
192
-
193
- )
194
-
195
- [original:protected] => Array
196
-
197
- (
198
-
199
- [school_name] => 沖縄
200
-
201
- )
202
-
203
- )
204
-
205
- ```
11
+ ▼理想のアウトプット
12
+
13
+ ``` 
14
+
15
+ <table>
16
+
17
+ <thead>
18
+
19
+ <tr>
20
+
21
+ <th>校舎住所1</th>
22
+
23
+ <th>校舎住所2</th>
24
+
25
+ </tr>
26
+
27
+ </thead>
28
+
29
+ <tbody>
30
+
31
+ <tr>
32
+
33
+ <td rowspan="3">大阪</td>
34
+
35
+ <td>123-14</td>
36
+
37
+ </tr>
38
+
39
+ <tr>
40
+
41
+ <td>123-15</td>
42
+
43
+ </tr>
44
+
45
+ <tr>
46
+
47
+ <td>123-16</td>
48
+
49
+ </tr>
50
+
51
+ <tr>
52
+
53
+ <td>長崎</td>
54
+
55
+ <td>123-14</td>
56
+
57
+ </tr>
58
+
59
+ <tr>
60
+
61
+ <td rowspan="2">沖縄</td>
62
+
63
+ <td>123-14</td>
64
+
65
+ </tr>
66
+
67
+ <tr>
68
+
69
+ <td>123-15</td>
70
+
71
+ </tr>
72
+
73
+ </tbody>
74
+
75
+ </table>
76
+
77
+ ```
78
+
79
+
80
+
81
+ foreachで前回の校舎住所1が同じ場合はrowspan用のデータを加えたいのですが
82
+
83
+ ひとつ前の比較しかできず、困っています。
84
+
85
+ どなたか解決方法ご存知の方いましたら教えていただけますと幸いです。
86
+
87
+
88
+
89
+ ▼これだと3件以上の重複に対応できていない。。
90
+
91
+ ``` 
92
+
93
+ $temp = "A";
94
+
95
+ foreach($schools as $key => $school){
96
+
97
+ if($school->school_location1 == $temp){
98
+
99
+ $schools[$key-1]->school->school_count++;
100
+
101
+ }
102
+
103
+ $temp = $school->school->school_location1;
104
+
105
+ }
106
+
107
+ ```
108
+
109
+ ▼元データ
110
+
111
+
112
+
113
+ ```
114
+
115
+ App\School Object
116
+
117
+ (
118
+
119
+ [attributes:protected] => Array
120
+
121
+ (
122
+
123
+ [school_location1] => 大阪
124
+
125
+ [school_location2] => 123-14
126
+
127
+ )
128
+
129
+ [original:protected] => Array
130
+
131
+ (
132
+
133
+ [school_location1] => 大阪
134
+
135
+ [school_location2] => 123-14
136
+
137
+ )
138
+
139
+ )
140
+
141
+ App\School Object
142
+
143
+ (
144
+
145
+ [attributes:protected] => Array
146
+
147
+ (
148
+
149
+ [school_location1] => 大阪
150
+
151
+ [school_location2] => 123-15
152
+
153
+ )
154
+
155
+ [original:protected] => Array
156
+
157
+ (
158
+
159
+ [school_location1] => 大阪
160
+
161
+ [school_location2] => 123-15
162
+
163
+ )
164
+
165
+ )
166
+
167
+ App\School Object
168
+
169
+ (
170
+
171
+ [attributes:protected] => Array
172
+
173
+ (
174
+
175
+ [school_location1] => 大阪
176
+
177
+ [school_location2] => 123-16
178
+
179
+ )
180
+
181
+ [original:protected] => Array
182
+
183
+ (
184
+
185
+ [school_location1] => 大阪
186
+
187
+ [school_location2] => 123-16
188
+
189
+ )
190
+
191
+ )
192
+
193
+ App\School Object
194
+
195
+ (
196
+
197
+ [attributes:protected] => Array
198
+
199
+ (
200
+
201
+ [school_location1] => 長崎
202
+
203
+ [school_location2] => 123-14
204
+
205
+ )
206
+
207
+ [original:protected] => Array
208
+
209
+ (
210
+
211
+ [school_location1] => 長崎
212
+
213
+ [school_location2] => 123-14
214
+
215
+ )
216
+
217
+ )
218
+
219
+ App\School Object
220
+
221
+ (
222
+
223
+ [attributes:protected] => Array
224
+
225
+ (
226
+
227
+ [school_location1] => 沖縄
228
+
229
+ [school_location2] => 123-14
230
+
231
+ )
232
+
233
+ [original:protected] => Array
234
+
235
+ (
236
+
237
+ [school_location1] => 沖縄
238
+
239
+ [school_location2] => 123-14
240
+
241
+ )
242
+
243
+ )
244
+
245
+ App\School Object
246
+
247
+ (
248
+
249
+ [attributes:protected] => Array
250
+
251
+ (
252
+
253
+ [school_location1] => 沖縄
254
+
255
+ [school_location2] => 123-15
256
+
257
+ )
258
+
259
+ [original:protected] => Array
260
+
261
+ (
262
+
263
+ [school_location1] => 沖縄
264
+
265
+ [school_location2] => 123-15
266
+
267
+ )
268
+
269
+ )
270
+
271
+ ```