By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

php function to ensure array is serially indexed

P: 77

I need to know if there is a built in php function that can tell me whether an array is serially indexed or not.
i.e. that all the keys range from 0 to ($count - 1)
I could use a for loop, but I would prefer a built in function (internally written in C).
so any one knows?

Mar 25 '10 #1
Share this Question
Share on Google+
4 Replies

Expert 5K+
P: 6,050
I don't believe there is. Can you explain in what context you'd need this functionality?
Mar 25 '10 #2

Expert Mod 5K+
P: 8,639
if everything else fails, you still could use each/foreach
Mar 25 '10 #3

P: 77
Expand|Select|Wrap|Line Numbers
  1. function isNumericallyIndexed($arr)
  2. {
  3.     return array_keys($arr) === range(0, count($arr) - 1);
  4. }
Jul 24 '10 #4

Expert Mod 5K+
P: 8,639
there are classes, that make sure you create an "array" with only numerical indices: SplFixedArray & SplDoublyLinkedList. though they’re nor suited to test an arbitrary array.
Jul 24 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.