回答編集履歴

1

追記

2016/08/24 23:57

投稿

ttyp03
ttyp03

スコア16998

test CHANGED
@@ -134,6 +134,188 @@
134
134
 
135
135
  }
136
136
 
137
-
138
-
139
- ```
137
+ ```
138
+
139
+
140
+
141
+ ---
142
+
143
+ 追記
144
+
145
+ ```PHP
146
+
147
+ $food1 = "猫缶"; //$_POST['food1']; //1つ目のselectのoptionのvalue
148
+
149
+ $food2 = "カリカリ"; //$_POST['food2']; //2つ目のselectのoptionのvalue
150
+
151
+
152
+
153
+ // 検索結果をショップ名をキーにした連想配列に詰める
154
+
155
+ $result["shop-a"][$food1][] = array("item"=>"猫缶A","price"=>100,"url"=>"http://...");
156
+
157
+ $result["shop-a"][$food1][] = array("item"=>"猫缶A(関東限定)","price"=>100,"url"=>"http://...");
158
+
159
+ $result["shop-a"][$food2][] = array("item"=>"猫缶B","price"=>150,"url"=>"http://...");
160
+
161
+ $result["shop-b"][$food1][] = array("item"=>"猫缶A","price"=>105,"url"=>"http://...");
162
+
163
+ $result["shop-c"][$food1][] = array("item"=>"猫缶A","price"=>98,"url"=>"http://...");
164
+
165
+ $result["shop-c"][$food2][] = array("item"=>"猫缶B","price"=>110,"url"=>"http://...");
166
+
167
+
168
+
169
+ // food1とfood2の両方の結果があるショップだけを抽出する
170
+
171
+ $result2 = array_filter($result, function($r){
172
+
173
+ return count($r)>=2;
174
+
175
+ });
176
+
177
+
178
+
179
+ // 並び替えの処理は、複数商品があった場合どうするかによるので今回は省略
180
+
181
+
182
+
183
+ var_dump($result2);
184
+
185
+ ```
186
+
187
+ 結果
188
+
189
+ ```
190
+
191
+ array(2) {
192
+
193
+ ["shop-a"]=>
194
+
195
+ array(2) {
196
+
197
+ ["猫缶"]=>
198
+
199
+ array(2) {
200
+
201
+ [0]=>
202
+
203
+ array(3) {
204
+
205
+ ["item"]=>
206
+
207
+ string(7) "猫缶A"
208
+
209
+ ["price"]=>
210
+
211
+ int(100)
212
+
213
+ ["url"]=>
214
+
215
+ string(10) "http://..."
216
+
217
+ }
218
+
219
+ [1]=>
220
+
221
+ array(3) {
222
+
223
+ ["item"]=>
224
+
225
+ string(21) "猫缶A(関東限定)"
226
+
227
+ ["price"]=>
228
+
229
+ int(100)
230
+
231
+ ["url"]=>
232
+
233
+ string(10) "http://..."
234
+
235
+ }
236
+
237
+ }
238
+
239
+ ["カリカリ"]=>
240
+
241
+ array(1) {
242
+
243
+ [0]=>
244
+
245
+ array(3) {
246
+
247
+ ["item"]=>
248
+
249
+ string(7) "猫缶B"
250
+
251
+ ["price"]=>
252
+
253
+ int(150)
254
+
255
+ ["url"]=>
256
+
257
+ string(10) "http://..."
258
+
259
+ }
260
+
261
+ }
262
+
263
+ }
264
+
265
+ ["shop-c"]=>
266
+
267
+ array(2) {
268
+
269
+ ["猫缶"]=>
270
+
271
+ array(1) {
272
+
273
+ [0]=>
274
+
275
+ array(3) {
276
+
277
+ ["item"]=>
278
+
279
+ string(7) "猫缶A"
280
+
281
+ ["price"]=>
282
+
283
+ int(98)
284
+
285
+ ["url"]=>
286
+
287
+ string(10) "http://..."
288
+
289
+ }
290
+
291
+ }
292
+
293
+ ["カリカリ"]=>
294
+
295
+ array(1) {
296
+
297
+ [0]=>
298
+
299
+ array(3) {
300
+
301
+ ["item"]=>
302
+
303
+ string(7) "猫缶B"
304
+
305
+ ["price"]=>
306
+
307
+ int(110)
308
+
309
+ ["url"]=>
310
+
311
+ string(10) "http://..."
312
+
313
+ }
314
+
315
+ }
316
+
317
+ }
318
+
319
+ }
320
+
321
+ ```