I'm a novice programmer and I'm a bit lost rigth now. I would like to get the data from "gameId" and save it into a variable.
我是一个新手程序员,现在我有点失去了。我想从“gameId”获取数据并将其保存到变量中。
printing $recentgames:
print_r($recentgames);
returns me this:
给我这个回报:
stdClass Object (
[summonerId] => 40300606,
[games] => Array (
[0] => stdClass Object (
[gameId] => 2102575613 ...
I want to store "2102575613" into $gamesid
. But my code does not work.
我想将“2102575613”存储到$ gamesid中。但我的代码不起作用。
$gamesid = $recentgames->array[0]->gameId;
//I have also tried this code
$gamesid = $recentgames->object->games->array[0]->gameId;
//and this one
$gamesid = $recentgames->$object->$games->$array[0]->gameId;
Any help would be highly appreciated.
任何帮助将受到高度赞赏。
1 个解决方案
#1
This should work:
这应该工作:
$recentgames->games[0]->gameId
You access objects with $object->property
and array like $array['key']
.
您可以使用$ object-> property和$ array ['key']等数组访问对象。
#1
This should work:
这应该工作:
$recentgames->games[0]->gameId
You access objects with $object->property
and array like $array['key']
.
您可以使用$ object-> property和$ array ['key']等数组访问对象。