-3

I'm very new to this and I need help. I have been searching and searching for days on end. My question is how to get it so my code I have here, returns just the values of one variable from inside the different object(stdClass)'s. Like I said I am very new and inexperienced with any sort of programming but I have self taught myself quite a bit.

Here is my current php code:

$rc = get_data('https://xboxapi.com/v2/2535433396471499/friends');
$rc2 = json_decode($rc);

Here is what I get when it is printed in the browser:

object(stdClass)#1 (13) {
["id"]=>
int(2535472804586102)
["hostId"]=>
NULL
["Gamertag"]=>
string(11) "Unikornz119"
["GameDisplayName"]=>
string(11) "Unikornz119"
["AppDisplayName"]=>
string(11) "Unikornz119"
["Gamerscore"]=>
int(3190)
["GameDisplayPicRaw"]=>
string(5) "a.png"
["AppDisplayPicRaw"]=>
string(180) "b.png"
["AccountTier"]=>
string(4) "Gold"
["XboxOneRep"]=>
string(10) "GoodPlayer"
["PreferredColor"]=>
string(0) ""
["TenureLevel"]=>
int(1)
["isSponsoredUser"]=>
bool(false)
}

Thank you all, I hope to hear some positive responses! :)

1
  • Incidentally, that is not actually an array. Commented Mar 11, 2016 at 0:01

1 Answer 1

0

Object properties are accessed like such:

$obj->property;

Array values are accessed like such:

$arr['key'];

So in your case, if you wanted to know the gamertag you'd look at $rc2->Gamertag

Alternatively, you can also tell json_decode to make the result an array by setting the second parameter of the function to true.

$rc = get_data('https://xboxapi.com/v2/2535433396471499/friends');
$rc2 = json_decode($rc, TRUE);

Then $rc2 would have an array and you could access $rc2['Gamertag'] instead.

Sign up to request clarification or add additional context in comments.

3 Comments

i set it all up but when i go to print the value it is blank and shows nothing. any idea whats wrong?
I tried both options and they both result the same.
I figured it out: just had to add the [0], [1], [2] part!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.