4

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. Thanks

2
  • 1
    with keys, do you mean only associative keys, e.g. those with a non-numeric index? For instance array('foo' => 'bar, 'baz') would return 1? Or you just want all keys? Commented Apr 27, 2010 at 12:11
  • 4
    google is your friend, but it'd better not be your only friend. When there is documentation available - and php has one of the best documentations I've ever read - use it. php.net/manual/en/ref.array.php Commented Apr 27, 2010 at 12:11

4 Answers 4

16

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);
Sign up to request clarification or add additional context in comments.

Comments

13
count(array_keys($array));

Comments

4

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);

Comments

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

http://lv.php.net/count

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.