我将一大堆数据填充到一个数组中(通过从memcache中提取或查询数据库)。我想计算这个数组中有多少行,以确保它大于0.当我使用count()时,它什么都不返回,即使数组中有数据也是如此。
为了排除故障,我尝试了以下代码:
$item_count=count($item_data);
print_r($item_data);
die($item_count);
这打印出一个巨大的数组,我可以看到有146个元素。但是$ item_count是NULL。知道什么可能是错的吗?谢谢!
根据评论中的要求,以下是我尝试计算的数组的示例:
Array
(
[0] => Array
(
[calories] => 190
[healthy_option] => 0
[name] => Chicken McNuggets
[url_name] => chicken-mcnuggets
[category_name] => Chicken Nuggets and Strips
[category_url_name] => chicken-nuggets-strips
[category_id] => 85
)
[1] => Array
(
[calories] => 380
[healthy_option] => 0
[name] => Chicken Selects Premium Breast Strips - 3 piece
[url_name] => chicken-selects-premium-breast-strips-3-piece
[category_name] => Chicken Nuggets and Strips
[category_url_name] => chicken-nuggets-strips
[category_id] => 85
)
)