json_decode array

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

object(stdClass)#210 (1) { [“http://www.domain.com”]=> object(stdClass)#211 (2) { [“id”]=> string(19) “http://www.domain.com” [“shares”]=> int(942) } }

You want to access the shares property of the object held in the [noparse]http://www.domain.com[/noparse] property of the $fb object. In multiple stages that would look like:

$object = $db->{$url};
$count  = $object->shares;

And in one line it would be:

$count = $fb->{$url}->shares;

If that is too confusing or unclear, another option is to return a nested array from json_decode() like:

$fb    = json_decode($output, TRUE);
$count = $fb[$url]['shares'];

It works when I use
$count = $fb->{“http://www.domain.com”}->shares;

but not with
$count = $fb->{$url}->shares;

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

Thanks. It works!!!