I populate a whole bunch of data into an array (either by pulling in from memcache or querying the database). I want to count how many rows are in this array to make sure it's greater than 0. When I use count(), it returns nothing, even when the array is full of data.
For troubleshooting, I tried the following code:
$item_count=count($item_data);
print_r($item_data);
die($item_count);
This prints out a huge array that I can see has 146 elements. But $item_count is NULL. Any idea what could be wrong? Thanks!
As requested in the comments, here's an example of what the array looks like that I'm trying to count:
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
)
)
countcan returnnull. Are you sure you're not mis-spelling something? If not, please provide replication example data.echo $item_countor avar_dump($item_count);die("$item_count");will work correctly