【问题标题】:get the data of an array in a stdClass Object获取 stdClass 对象中数组的数据
【发布时间】:2015-05-12 13:18:05
【问题描述】:

我是一个新手程序员,我现在有点迷失方向。我想从“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; 

任何帮助将不胜感激。

【问题讨论】:

  • $gamesid=$recentgames->games[0]->gameId;
  • 成功了,非常感谢

标签: php arrays object stdclass


【解决方案1】:

这应该可行:

$recentgames->games[0]->gameId

您使用$object->property 和数组访问对象,例如$array['key']

【讨论】:

    猜你喜欢
    • 2014-05-04
    • 2021-02-07
    • 1970-01-01
    • 2017-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多