【发布时间】:2018-04-02 13:40:33
【问题描述】:
如何从“gameid”存在且值为“730”的玩家那里获得所有“steamids”?
它显示:
注意 未定义的属性:第 31 行的 stdClass::$gameid
因为“gameid”并不存在于每个元素中
代码:
$players = json_decode(file_get_contents("test.json"));
foreach($players->response->Players as $mydata)
{
if($players->gameid == "730"){
echo $mydata->steamid . "\n";
}
}
我的 json:
{
"response": {
"players": [
{
"steamid": "76561198273176399",
"loccountrycode": "US"
},
{
"steamid": "76561198386141115",
"gameid": "730",
"loccountrycode": "DE"
},
{
"steamid": "76561198019025166",
"gameid": "730",
"loccountrycode": "RU"
},
{
"steamid": "76561198010529217",
"loccountrycode": "DK"
}
]
}
}
非常感谢。致以最诚挚的问候。
【问题讨论】:
-
在 foreach 和
if($mydata->gameid中以小写字母开头players -
@splash58 谢谢,但它告诉我:通知未定义的属性:第 31 行的 stdClass::$gameid 因为“gameid”并不存在于每个元素中