Reputation: 244
This works and is tested. PHP Code:
$data_stats = json_decode($ret);
$projected_points = $data_stats->body->player_stats->42550689->FPTS
I just need to know how to do it using a variable. Something like this: PHP Code:
$data_stats = json_decode($ret);
$projected_points = $data_stats->body->player_stats->$id->FPTS
How can I make $id work here?
Also is this called extending a class? I don't even know the correct terminology to describe my question.
Upvotes: 2
Views: 59
Reputation: 55962
I believe you can access attributes using alternative syntax $obj->player_stats->{$var}
Upvotes: 3
Reputation: 8690
You're looking for a variable variable... something like:
$yourId = 42550689
Then, you do:
$projected_points = $data_stats->body->player_stats->$$yourId->FPTS
Check the docs for more info: http://www.php.net/manual/en/language.variables.variable.php
Upvotes: 0