php - Filtering through json array -


i have json array

http://paste.ofcode.org/wxs7ra35zjzk9wtuh7t3eh

it represents trade offer steam. every offer has "items_to_give" , "items_to_receive".

i want json array this

{ "items_to_give": [                 {                     "market_hash_name": "awp | asiimov (field-tested)",                 },                 {                     "market_hash_name": "m4a4 | asiimov (field-tested)"                   }                  ]             ,  "items_to_receive": [                 {                     "market_hash_name": "★ falchion knife | blue steel (field-tested)"                 }                                           ] } 

every item has unique "classid" , "instanceid" "market_hash_name" shown in "descriptions" part of array.

first have find name using "classid" , "instanceid" , move "items_to_give" , "items_to_receive" .

here photo showing mean . enter image description here

just make file , test it. think can it.

the result this:

{     "items_to_give": [         {             "instanceid": "480085569",             "classid": "1440311074",             "assetid": "5003822520",             "amount": "1",             "market_hash_name": "awp | asiimov (field-tested)",             "market_name": "awp | asiimov (field-tested)",             "name": "awp | asiimov",             "icon_url": "-9a81dlwlwj2uugcvs_nsvtzdoedtwwkgzzlqhtxdz7i56ku0zwwo4nux4ofjzehlbxh5apeo4ymlhxyqkncrvco04devlxkkgpot621far17plfyqjd_9w7m5a0mvlwoq7c2g9supuijojaotyg3w2x_0zkz2rzd4oxdgroyque8gdtyl_mg5k4tj7xisw0wqkv8km",             "action_link": "steam:\/\/rungame\/730\/76561202255233023\/+csgo_econ_action_preview%20s%owner_steamid%a%assetid%d9394689721994738281"         },         {             "instanceid": "188530139",             "classid": "310777979",             "assetid": "4999225449",             "amount": "1",             "market_hash_name": "m4a4 | asiimov (field-tested)",             "market_name": "m4a4 | asiimov (field-tested)",             "name": "m4a4 | asiimov",             "icon_url": "-9a81dlwlwj2uugcvs_nsvtzdoedtwwkgzzlqhtxdz7i56ku0zwwo4nux4ofjzehlbxh5apeo4ymlhxyqkncrvco04devlxkkgpou-6kejhjxszfjqjd_9w7m5a0mvlwoq7c2gluucfwjrur9t7231dmrrc_nw7yitcrcvnoyvhs-aprwbzu0jk-78nxisw0enwdrm0",             "action_link": "steam:\/\/rungame\/730\/76561202255233023\/+csgo_econ_action_preview%20s%owner_steamid%a%assetid%d459488816407887944"         }     ],     "items_to_receive": [         {             "instanceid": "188530139",             "classid": "1015898744",             "assetid": "5004700589",             "amount": "1",             "market_hash_name": "\u2605 falchion knife | blue steel (field-tested)",             "market_name": "\u2605 falchion knife | blue steel (field-tested)",             "name": "\u2605 falchion knife | blue steel",             "icon_url": "-9a81dlwlwj2uugcvs_nsvtzdoedtwwkgzzlqhtxdz7i56ku0zwwo4nux4ofjzehlbxh5apeo4ymlhxyqkncrvco04devlxkkgpovbsslqjf1flecjvl49kjlzg0lfvhnr_um25v4db8xorapdqmjabi_hftygr7cicudvvtna6d81m9yobr0cdotjnjnsm3viu8psgkml5fgrg",             "action_link": "steam:\/\/rungame\/730\/76561202255233023\/+csgo_econ_action_preview%20s%owner_steamid%a%assetid%d14288283571522546212"         }     ] } 

if response same http://paste.ofcode.org/wxs7ra35zjzk9wtuh7t3eh

i put needed on code. because steam user also. :d

<?php $steamresponse = '{     "response": {         "trade_offers_received": [             {                 "tradeofferid": "993371789",                 "accountid_other": 254083372,                 "message": "i got fantastic idea. make between us.          ;)",                 "expiration_time": 1455660736,                 "trade_offer_state": 7,                 "items_to_give": [                     {                         "appid": "730",                         "contextid": "2",                         "assetid": "5003822520",                         "classid": "1440311074",                         "instanceid": "480085569",                         "amount": "1",                         "missing": false                     },                     {                         "appid": "730",                         "contextid": "2",                         "assetid": "4999225449",                         "classid": "310777979",                         "instanceid": "188530139",                         "amount": "1",                         "missing": false                     }                 ]                 ,                 "items_to_receive": [                     {                         "appid": "730",                         "contextid": "2",                         "assetid": "5004700589",                         "classid": "1015898744",                         "instanceid": "188530139",                         "amount": "1",                         "missing": false                     }                 ]                 ,                 "is_our_offer": false,                 "time_created": 1454451136,                 "time_updated": 1454451250,                 "from_real_time_trade": false,                 "escrow_end_date": 0,                 "confirmation_method": 0             }         ]         ,         "descriptions": [             {                 "appid": 730,                 "classid": "1440311074",                 "instanceid": "480085569",                 "currency": false,                 "background_color": "",                 "icon_url": "-9a81dlwlwj2uugcvs_nsvtzdoedtwwkgzzlqhtxdz7i56ku0zwwo4nux4ofjzehlbxh5apeo4ymlhxyqkncrvco04devlxkkgpot621far17plfyqjd_9w7m5a0mvlwoq7c2g9supuijojaotyg3w2x_0zkz2rzd4oxdgroyque8gdtyl_mg5k4tj7xisw0wqkv8km",                 "icon_url_large": "-9a81dlwlwj2uugcvs_nsvtzdoedtwwkgzzlqhtxdz7i56ku0zwwo4nux4ofjzehlbxh5apeo4ymlhxyqkncrvco04devlxkkgpot621far17plfyqjd_9w7m5a0mvlwoq7cqwdq-sj0xozaot-jiqa3-hbqyzvzldsvjlq3nqvr-ffsxl3qh5e7vm6bzsa26sg8psgkjupenty",                 "descriptions": [                     {                         "type": "html",                         "value": "exterior: field-tested"                     },                     {                         "type": "html",                         "value": " "                     },                     {                         "type": "html",                         "value": "high risk , high reward, infamous awp recognizable signature report , one-shot, one-kill policy. has been custom painted sci-fi design.\n\n<i>anyone can predict future... visionary shapes it</i>"                     },                     {                         "type": "html",                         "value": " "                     },                     {                         "type": "html",                         "value": "the phoenix collection",                         "color": "9da1a9"                     },                     {                         "type": "html",                         "value": " "                     },                     {                         "type": "html",                         "value": "<br><div id=\"sticker_info\" name=\"sticker_info\" title=\"sticker details\" style=\"border: 2px solid rgb(102, 102, 102); border-radius: 6px; width=100; margin:4px; padding:8px;\"><center><img width=64 height=48 src=\"https://steamcdn-a.akamaihd.net/apps/730/icons/econ/stickers/team_roles_capsule/baiter.f14ba197e75a0b0074c74e7f98af9eb4d111981b.png\"><img width=64 height=48 src=\"https://steamcdn-a.akamaihd.net/apps/730/icons/econ/stickers/team_roles_capsule/lurker.850f26af6a1e55f4ed398da610d9ceb73ce0b338.png\"><img width=64 height=48 src=\"https://steamcdn-a.akamaihd.net/apps/730/icons/econ/stickers/team_roles_capsule/awper.251e754fcfd1d398fcedc220dc44f479b841c8ea.png\"><br>sticker: baiter, lurker, awper</center></div>"                     }                 ]                 ,                 "tradable": true,                 "actions": [                     {                         "link": "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20s%owner_steamid%a%assetid%d9394689721994738281",                         "name": "inspect in game..."                     }                 ]                 ,                 "name": "awp | asiimov",                 "name_color": "d2d2d2",                 "type": "covert sniper rifle",                 "market_name": "awp | asiimov (field-tested)",                 "market_hash_name": "awp | asiimov (field-tested)",                 "market_actions": [                     {                         "link": "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20m%listingid%a%assetid%d9394689721994738281",                         "name": "inspect in game..."                     }                 ]                 ,                 "commodity": false,                 "market_tradable_restriction": 7             },             {                 "appid": 730,                 "classid": "310777979",                 "instanceid": "188530139",                 "currency": false,                 "background_color": "",                 "icon_url": "-9a81dlwlwj2uugcvs_nsvtzdoedtwwkgzzlqhtxdz7i56ku0zwwo4nux4ofjzehlbxh5apeo4ymlhxyqkncrvco04devlxkkgpou-6kejhjxszfjqjd_9w7m5a0mvlwoq7c2gluucfwjrur9t7231dmrrc_nw7yitcrcvnoyvhs-aprwbzu0jk-78nxisw0enwdrm0",                 "icon_url_large": "-9a81dlwlwj2uugcvs_nsvtzdoedtwwkgzzlqhtxdz7i56ku0zwwo4nux4ofjzehlbxh5apeo4ymlhxyqkncrvco04devlxkkgpou-6kejhjxszfjqjd_9w7m5a0mvlwoq7cqwdq-sj0xovepij0jabkqee_zd3xctlgjae_zw7u-qtowefth8tpvm_inhzh6xq8psgkwyjaoji",                 "descriptions": [                     {                         "type": "html",                         "value": "exterior: field-tested"                     },                     {                         "type": "html",                         "value": " "                     },                     {                         "type": "html",                         "value": "more accurate less damaging ak-47 counterpart, m4a4 full-auto assault rifle of choice cts. has been custom painted sci-fi design.\n\n<i>anyone can predict future... visionary shapes it</i>"                     },                     {                         "type": "html",                         "value": " "                     },                     {                         "type": "html",                         "value": "the winter offensive collection",                         "color": "9da1a9"                     },                     {                         "type": "html",                         "value": " "                     }                 ]                 ,                 "tradable": true,                 "actions": [                     {                         "link": "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20s%owner_steamid%a%assetid%d459488816407887944",                         "name": "inspect in game..."                     }                 ]                 ,                 "name": "m4a4 | asiimov",                 "name_color": "d2d2d2",                 "type": "covert rifle",                 "market_name": "m4a4 | asiimov (field-tested)",                 "market_hash_name": "m4a4 | asiimov (field-tested)",                 "market_actions": [                     {                         "link": "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20m%listingid%a%assetid%d459488816407887944",                         "name": "inspect in game..."                     }                 ]                 ,                 "commodity": false,                 "market_tradable_restriction": 7             },             {                 "appid": 730,                 "classid": "1015898744",                 "instanceid": "188530139",                 "currency": false,                 "background_color": "",                 "icon_url": "-9a81dlwlwj2uugcvs_nsvtzdoedtwwkgzzlqhtxdz7i56ku0zwwo4nux4ofjzehlbxh5apeo4ymlhxyqkncrvco04devlxkkgpovbsslqjf1flecjvl49kjlzg0lfvhnr_um25v4db8xorapdqmjabi_hftygr7cicudvvtna6d81m9yobr0cdotjnjnsm3viu8psgkml5fgrg",                 "icon_url_large": "-9a81dlwlwj2uugcvs_nsvtzdoedtwwkgzzlqhtxdz7i56ku0zwwo4nux4ofjzehlbxh5apeo4ymlhxyqkncrvco04devlxkkgpovbsslqjf1flecjvl49kjlzg0lfvhnr_um25v4db8texa54vwxle1-0vvn2v1idsucqu2nv7r_qltlli8jj6_tzxnnsq3siqiss6jmxcpwuybioval6a",                 "descriptions": [                     {                         "type": "html",                         "value": "exterior: field-tested"                     },                     {                         "type": "html",                         "value": " "                     },                     {                         "type": "html",                         "value": "a modern homage falchion sword, clip point blade has curved edge. has been cold blued.\n\n<i>this malbec of weapon design - booth, arms dealer</i>"                     },                     {                         "type": "html",                         "value": " "                     }                 ]                 ,                 "tradable": true,                 "actions": [                     {                         "link": "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20s%owner_steamid%a%assetid%d14288283571522546212",                         "name": "inspect in game..."                     }                 ]                 ,                 "name": "★ falchion knife | blue steel",                 "name_color": "8650ac",                 "type": "★ covert knife",                 "market_name": "★ falchion knife | blue steel (field-tested)",                 "market_hash_name": "★ falchion knife | blue steel (field-tested)",                 "market_actions": [                     {                         "link": "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20m%listingid%a%assetid%d14288283571522546212",                         "name": "inspect in game..."                     }                 ]                 ,                 "commodity": false,                 "market_tradable_restriction": 7             }         ]      } }';   $json = json_decode($steamresponse); // $steamresponse json response steam  $result = array(); $result['items_to_give'] = array(); $result['items_to_receive'] = array();   foreach($json->response->trade_offers_received[0]->items_to_give $key => $value){     $result['items_to_give'][$key]['instanceid'] = $value->instanceid;     $result['items_to_give'][$key]['classid'] = $value->classid;     $result['items_to_give'][$key]['assetid'] = $value->assetid;     $result['items_to_give'][$key]['amount'] = $value->amount;      foreach($json->response->descriptions $key2 => $value2){         if(($value2->instanceid == $value->instanceid) && ($value2->classid == $value->classid)){             $result['items_to_give'][$key]['market_hash_name'] = $value2->market_hash_name;             $result['items_to_give'][$key]['market_name'] = $value2->market_name;             $result['items_to_give'][$key]['name'] = $value2->name;             $result['items_to_give'][$key]['icon_url'] = $value2->icon_url;             $result['items_to_give'][$key]['action_link'] = $value2->actions[0]->link;         }     } }  foreach($json->response->trade_offers_received[0]->items_to_receive $key => $value){     $result['items_to_receive'][$key]['instanceid'] = $value->instanceid;     $result['items_to_receive'][$key]['classid'] = $value->classid;     $result['items_to_receive'][$key]['assetid'] = $value->assetid;     $result['items_to_receive'][$key]['amount'] = $value->amount;     foreach($json->response->descriptions $key2 => $value2){         if(($value2->instanceid == $value->instanceid) && ($value2->classid == $value->classid)){             $result['items_to_receive'][$key]['market_hash_name'] = $value2->market_hash_name;             $result['items_to_receive'][$key]['market_name'] = $value2->market_name;             $result['items_to_receive'][$key]['name'] = $value2->name;             $result['items_to_receive'][$key]['icon_url'] = $value2->icon_url;             $result['items_to_receive'][$key]['action_link'] = $value2->actions[0]->link;         }     } }   echo '<pre>'; print_r(json_encode($result, json_pretty_print)); echo '</pre>'; 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -