原文:http://www.ejeliot.com/blog/86
The other day I was working on an application which uses PHP's built in JSON libraries to parse data returned from the del.icio.us APIs. The JSON libraries return tag data for each post as an object rather than an array as shown below:
stdClass Object(
[css] => 549
[webdesign] => 136
[web] => 75
[floats] => 113
[webdev] => 36
)
This means that you can't directly use the count() function to work out the number of tags associated with a particular post. The following won't work:
$iCount = count($oTags);
Luckily the solution is very straight forward - simply cast the object to an array before calling count:
$iCount = count((array)$oTags);