Hello. I am trying to use steam web API to access my steam inventory and report it to my website page. This is part of what I am originally returned.
{
"result": {
"status": 1,
"num_backpack_slots": 150,
"items": [
{
"id": 1828738510,
"original_id": 1828738510,
"defindex": 166,
"level": 5,
"quality": 6,
"inventory": 2147483649,
"quantity": 1,
"origin": 0,
"flag_cannot_trade": true,
"attributes": [
{
"defindex": 143,
"value": 1373392596,
"float_value": 118276915200.000000
},
{
"defindex": 292,
"value": 1115684864,
"float_value": 64.000000
},
{
"defindex": 388,
"value": 1115684864,
"float_value": 64.000000
},
{
"defindex": 153,
"value": 1065353216,
"float_value": 1.000000
}
]
},
{
"id": 1828947688,
"original_id": 1176490973,
"defindex": 5009,
"level": 1,
"quality": 6,
"inventory": 2147483650,
"quantity": 1,
"origin": 4
},
{
"id": 1828947700,
"original_id": 1176491289,
"defindex": 5009,
"level": 1,
"quality": 6,
"inventory": 2147483651,
"quantity": 1,
"origin": 4
},
{
"id": 1828947742,
"original_id": 1178541917,
"defindex": 5009,
"level": 1,
"quality": 6,
"inventory": 2147483652,
"quantity": 1,
"origin": 4
},
{
"id": 1828947755,
"original_id": 1178542060,
"defindex": 5009,
"level": 1,
"quality": 6,
"inventory": 2147483757,
"quantity": 1,
"origin": 4
},
And so on.
What I would like to do is loop through this data for all of the defindexes of 5001 and count those up and then print them. So far this is my code. Ignore the [insert_php], that is what my WordPress plugin uses to start/end it.
$api = "http://api.steampowered.com/IEconItems_440/GetPlayerItems/v0001/?key=key+removed&steamid=id+removed&format=json";
$json = file_get_contents($api);
$schema = json_decode($json, true);
$total_metal = 0;
foreach($schema as $item)
{
if (in_array($item->defindex, $schema));
{
if($item->defindex == 5001);
{
$total_metal+= 3;
}
if($item->defindex == 5002);
{
$total_metal+= 9;
}
}
}
print $total_metal;
So far I am only returned 12 when I should be returned 63. Any help here would be great. Thanks.
MOD EDIT: [noparse][insert_php]..[/insert_php] changed to the more useful bbcode tags
..
[/noparse] - please use these in the future. Also, the 'key' in the URL is probably meant to be kept private and not given out.