Php 获取stdClass对象中数组的数据
我是一个新手程序员,现在有点迷失了方向。我想从“gameId”中获取数据并将其保存到变量中 打印$recentgames:Php 获取stdClass对象中数组的数据,php,arrays,object,stdclass,Php,Arrays,Object,Stdclass,我是一个新手程序员,现在有点迷失了方向。我想从“gameId”中获取数据并将其保存到变量中 打印$recentgames: print_r($recentgames); 给我这个: stdClass Object ( [summonerId] => 40300606, [games] => Array ( [0] => stdClass Object ( [gameId] => 2102575613 ... 我想
print_r($recentgames);
给我这个:
stdClass Object (
[summonerId] => 40300606,
[games] => Array (
[0] => stdClass Object (
[gameId] => 2102575613 ...
我想将“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;
非常感谢您的帮助。这应该可以:
$recentgames->games[0]->gameId
您可以使用
$object->property
和类似$array['key']
$gamesid=$recentgames->games[0]->gamesid的数组访问对象代码>很有效,非常感谢