1 回答
TA贡献1825条经验 获得超6个赞
由于这是一个 json 响应,因此您首先需要对其进行解码json_decode,然后将其视为数组。
$decode = json_decode($data,true); //$data is your json response
$result = [];
for ($i=0; $i < sizeof($decode['result_user_wish_list']['my_whishlist']) ; $i++) {
for ($j=0; $j < sizeof($decode['result_user_wish_list']['my_friends_list'][0]) ; $j++) {
if ($decode['result_user_wish_list']['my_whishlist'][$i]['shop_name'] == $decode['result_user_wish_list']['my_friends_list'][0][$j]['shop_name'] &&
$decode['result_user_wish_list']['my_whishlist'][$i]['shop_zipcode'] == $decode['result_user_wish_list']['my_friends_list'][0][$j]['shop_zipcode']) {
$result[$decode['result_user_wish_list']['my_whishlist'][$i]['shop_name']][] = $decode['result_user_wish_list']['my_whishlist'][$i];
$result[$decode['result_user_wish_list']['my_whishlist'][$i]['shop_name']][] = $decode['result_user_wish_list']['my_friends_list'][0][$j];
}
else{
$result[$decode['result_user_wish_list']['my_whishlist'][$i]['shop_name']][] = $decode['result_user_wish_list']['my_whishlist'][$i];
}
}
}
输出
Array
(
[Relience] => Array
(
[0] => Array
(
[id] => 6
[product_name] => abc
[price] => 300
[user_id] => 6
[shop_name] => Relience
[is_buy] => 0
[purchase_by] =>
[created_at] => 2020-07-01T21:34:43.000000Z
[updated_at] => 2020-07-01T21:34:43.000000Z
[shop_zipcode] => 390016
[user_name] => ABC
)
[1] => Array
(
[id] => 2
[product_name] => Rice
[price] => 1200
[user_id] => 1
[shop_id] => 12
[is_buy] => 0
[purchase_by] =>
[created_at] => 2020-06-16T12:02:04.000000Z
[updated_at] => 2020-07-03T16:06:42.000000Z
[shop_name] => Relience
[shop_zipcode] => 390016
[user_name] => MNJ
)
)
[Dmart] => Array
(
[0] => Array
(
[id] => 2
[product_name] => Rice
[price] => 1200
[user_id] => 1
[shop_id] => 10
[is_buy] => 0
[purchase_by] =>
[created_at] => 2020-06-16T12:02:04.000000Z
[updated_at] => 2020-07-03T16:06:42.000000Z
[shop_name] => Dmart
[shop_zipcode] => 390017
[user_name] => XYZ
)
)
)
- 1 回答
- 0 关注
- 116 浏览
添加回答
举报