您的位置:首页 > 移动开发 > Objective-C

PHP Tip: Getting the property count for an object

2007-06-02 00:16 543 查看
原文: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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐