获取 stdClass 对象中数组的数据

get the data of an array in a stdClass Object

我是一名新手程序员,现在有点迷路。我想从 "gameId" 获取数据并将其保存到变量中。

正在打印 $recentgames:

print_r($recentgames);

returns 我这个:

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'] 这样的数组访问对象。