-1

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.

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.

$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.

VeeeneX
  • 1,556
  • 18
  • 26
juan fran
  • 359
  • 3
  • 12

1 Answers1

1

This should work:

$recentgames->games[0]->gameId

You access objects with $object->property and array like $array['key'].

Florian
  • 2,796
  • 1
  • 15
  • 25