Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 获取stdClass对象中数组的数据_Php_Arrays_Object_Stdclass - Fatal编程技术网

Php 获取stdClass对象中数组的数据

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 ... 我想

我是一个新手程序员,现在有点迷失了方向。我想从“gameId”中获取数据并将其保存到变量中

打印$recentgames:

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的数组访问对象很有效,非常感谢