Php - is it possible to count the number of keys in an array?

I searched for this but did not find any answers, so I guess this is not possible. If there is a way, I would like to know. Thanks to

+2


a source to share


4 answers


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



$numKeys = count($array);

      

+11


a source


count(array_keys($array));

      



+11


a source


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

      

http://lv.php.net/count

+3


a source


Array as long as its keys, you can use any of count

or sizeof

for example

echo count($your_array);

      

or

echo sizeof($your_array);

      

+3


a source







All Articles