views:

199

answers:

4

Possible Duplicate:
PHP Arrays: A good way to check if an array is associative or sequential?

What would be the most performant way of checking if an array is associative or not in PHP?

A: 

If it is for the purpose of iterating through an array, to be safe you can always use foreach.

Extrakun
I know, but it's not.
Alix Axel
A: 
is_int(key($someArray))
Vincent W
consider array('foo'=>'bar',27=>'Hello')
Alan Storm
I know. But because this is all just a concept (indexed or associative), you can also choose to never use mixed arrays (with both integer and string indices). If you would adhere to these principles, the code above would suffice.
Vincent W
It's slightly more than a concept. Although there's a single Array type in PHP, many of the built in functions will operate differently on an array with a series of sequential integers than they will on a array with a non-sequential series of mixed keys.
Alan Storm
+4  A: 

I think you are looking for - http://stackoverflow.com/questions/173400/php-arrays-a-good-way-to-check-if-an-array-is-associative-or-sequential

adatapost
+1 Thank you, finally someone has provided me with an answer other lecturing me about what arrays in PHP are and aren't. ~_~
Alix Axel
A: 

There are only associative arrays in PHP.

Bombe