PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
pedroz
Forum Commoner
Posts: 99 Joined: Thu Nov 03, 2005 6:21 am
Post
by pedroz » Sun Mar 13, 2011 6:34 pm
Code: Select all
$url = 'http://www.domain.com';
$fb = json_decode($output);
$count = $fb->{$url}{'shares'};
echo $count; // should be 942
to get the 942 result, what am i doing wrong?
Code: Select all
var_dump($output);
object(stdClass)#210 (1) {
["http://www.domain.com"]=> object(stdClass)#211 (2) {
["id"]=> string(19) "http://www.domain.com"
["shares"]=> int(942)
}
}
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Sun Mar 13, 2011 6:44 pm
Code: Select all
$count = $fb->{"http://www.domain.com"}->{"shares"};
pedroz
Forum Commoner
Posts: 99 Joined: Thu Nov 03, 2005 6:21 am
Post
by pedroz » Sun Mar 13, 2011 7:29 pm
Thanks.
It works when I use
$count = $fb->{"http://www.domain.com"}->shares;
but not with
$count = $fb->{$url}->shares;
pedroz
Forum Commoner
Posts: 99 Joined: Thu Nov 03, 2005 6:21 am
Post
by pedroz » Sun Mar 13, 2011 7:31 pm
Sorry. I had 2 $url strings in the function messing it.
Thanks. It works!!!!