我正在使用蒸汽API來循環通過揹包中的物品。這是我返回的部分。多維數組循環
{
"result": {
"status": 1,
"num_backpack_slots": 900,
"items": [
{
"id": 1828738510,
"original_id": 1828738510,
"defindex": 166,
"level": 5,
"quality": 6,
"inventory": 2147484295,
"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": 1828947755,
"original_id": 1178542060,
"defindex": 5009,
"level": 1,
"quality": 6,
"inventory": 2147484021,
"quantity": 1,
"origin": 4
},
{
"id": 1828947766,
"original_id": 1179066746,
"defindex": 5005,
"level": 1,
"quality": 6,
"inventory": 2147483798,
"quantity": 1,
"origin": 4
},
{
"id": 1828947780,
"original_id": 1181421843,
"defindex": 5009,
"level": 1,
"quality": 6,
"inventory": 2147484020,
"quantity": 1,
"origin": 4
},
依此類推。
我想要做的是通過這個爲我的defindex使用foreach(或其他工程)循環。這是我當前的代碼:
<?php
$api = "http://api.steampowered.com/IEconItems_440/GetPlayerItems/v0001/? key=MyApiKey&steamid=MySteamId&format=json";
$json = (file_get_contents($api));
$schema = json_decode($json);
$total_metal = 0;
if ($schema-> result -> items[0] -> defindex == 5000)
{
$total_metal++;
}
if ($schema-> result -> items[0] -> defindex == 5001)
{
$total_metal+= 3;
}
if ($schema-> result -> items[0] -> defindex == 5002)
{
$total_metal+= 9;
}
print $total_metal;
?>
到目前爲止,這返回0,因爲第一個變量不是第一個這些defindex中的任何一個。我需要做的是讓這三個實例遍歷整個陣列。從我看到的,我需要爲每一個內部寫一個,但環顧四周,我無法找到任何能夠幫助我的東西。提前致謝。