0

so...

I started to develop simple tf2 inventory and get API.

I'm getting the defindexs from tf2 api

$link = file_get_contents("http://api.steampowered.com/IEconItems_440/GetPlayerItems/v0001/?key=" . $api_key . "&steamid=" . $id . "&format=json");
$myarray = json_decode($link, true);      

print $myarray['result']['items']['0']['defindex'];

Schema from here: file_get_contents("http://api.steampowered.com/IEconItems_440/GetSchema/v0001/?key=" . $api_key . "");

I printed $myarray and result is: 261

So, I have 2 questions:

How I can print all defindexs to my page?

and

How I can replace defindexs with name of weapon from GetSchema?

dokaspar
  • 8,186
  • 14
  • 70
  • 98
Krancik
  • 25
  • 5
  • 1) Using loops. Try `var_dump($myarray)` to see what in there and how to loop. Read the manual if you don't know how to use `foreach`. 2) Again, see your entire data to see if maybe the information is already there. Otherwise, look at the Steam API documentation. This is only tangentially something we can help you with here. – deceze Jan 24 '15 at 09:49

1 Answers1

1

How to print all defindexes:

Go through each item using foreach

foreach($myarray['result']['items'] as $item)
{
    echo $item['defindex'].'<br />';
}

How to replace items defindexes by their names:

Firs of all you have to add GET paramater language=en to GetSchema request link, so GetSchema will return correct item names.

file_get_contents("http://api.steampowered.com/IEconItems_440/GetSchema/v0001/?language=en&key=" . $api_key . "");

Then go through each item again like in your first question. Inside each item iterration go through each item in schema and compare defindexes. If they are match, you founded your item in schema. Print 'item_name' paramether. Don't forget about break your second foreach, because schema array is big. Example code:

foreach($myarray['result']['items'] as $item)
{
    foreach($schema['result']['items'] as $schemaItem)
    {
        if($item['defindex'] == $schemaItem['defindex'])
        {
            echo $schemaItem['item_name'].'<br />';
            break;
        }
    }
}