首先,你有无效的json.请参阅下面的字符串减速中的注释(这可能是您问题中的拼写错误).
$json = '{
"response": {
"game_count": 106,
"games": [
{
"appid": 10,
"playtime_forever": 67
},
{
"appid": 730,
"playtime_forever": 0
},
{
"appid": 368900,
"playtime_forever": 0
},
{
"appid": 370190,
"playtime_forever": 0
} //
]
}
}';
$arr = json_decode($json, true);
foreach($arr['response']['games'] as $game) {
if($game['appid'] === 730) { // I would strictly check (type) incase of 0
echo "exists"; // or do something else
break; // break out if you dont care about the rest
}
}
我们只是循环遍历游戏阵列并检查其appid.然后我们只是做一些事情然后打破循环以防止开销.