开发者

php - Is it possible to count the number of keys in an array?

I've googled this but found no answers, so I guess it's not possible. If there is a way, I'd love to know it.开发者_StackOverflow Thanks


The number of keys in the array will always be the number of elements in the array, as the keys must be unique. So:

$numKeys = count($array);


count(array_keys($array));


Array is as long as its keys, you can use either of count or sizeof eg

echo count($your_array);

or

echo sizeof($your_array);


$array = array('one', 'two', 'three');
echo count($array);

http://lv.php.net/count

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜