开发者

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

开发者 https://www.devze.com 2022-12-28 20:49 出处:网络
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 ThanksThe number of keys in the array will always be the number of

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

精彩评论

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

关注公众号