Search code examples
phpjsonsteamsteam-web-api

Steam Inventory in PHP from json


so basically Im trying to get steam player inventory in PHP from geting json content but I cannot figure out how to do it, espcially I didn't work with json a lot before. I have a problem with what I should pick in PHP to get what I want from the JSON.

PHP:

    $inventoryJsonUrl = 'http://steamcommunity.com/inventory/'.$steamID.'/730/2?l=english&count=5000';
    $inventoryJsonGet = file_get_contents($inventoryJsonUrl);
    $inventory = json_decode($inventoryJsonGet, TRUE);

for ($i=0; $i < count($inventory['assets']) ; $i++) { echo $inventory['assets']; }

And lets say the $inventoryJsonURL is now http://steamcommunity.com/inventory/76561198260345960/730/2?l=english&count=5000

And I have problem with getting what I want, I mean lets say that in the for loop I want to have name of the item/skin, id of that item and some more things. But I don't know how and what I suppose to pick to get that.

Sorry for bad bad English.

Thanks in advance.


Solution

  • You can make use of PHP's foreach loop.

    $inventories = json_decode($inventoryJsonGet , TRUE);
    
    // you can check the structure of your array by 
    // print_r($inventories)
    foreach ($inventories['descriptions'] as $key => $description) {
        echo '<pre>';
        echo $description['appid'];
        echo $description['market_name'];
        echo '</pre>';
    }