json_decode array

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

Post Reply
pedroz
Forum Commoner
Posts: 99
Joined: Thu Nov 03, 2005 6:21 am

json_decode array

Post by pedroz »

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) 
    } 
}
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: json_decode array

Post by Weirdan »

Code: Select all

$count = $fb->{"http://www.domain.com"}->{"shares"};
pedroz
Forum Commoner
Posts: 99
Joined: Thu Nov 03, 2005 6:21 am

Re: json_decode array

Post by pedroz »

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

Re: json_decode array

Post by pedroz »

Sorry. I had 2 $url strings in the function messing it.

Thanks. It works!!!!
Post Reply