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

Posted by Wilco on Stack Overflow See other posts from Stack Overflow or by Wilco
Published on 2008-10-06T07:01:13Z Indexed on 2010/03/15 2:09 UTC
Read the original article Hit count: 315

Filed under:
|

PHP treats all arrays as associative, so there aren't any built in functions. Can anyone recommend a fairly efficient way to check if an array contains only numeric keys?

Basically, I want to be able to differentiate between this:

$sequentialArray = array('apple', 'orange', 'tomato', 'carrot');

and this:

$assocArray = array('fruit1' => 'apple', 
                    'fruit2' => 'orange', 
                    'veg1' => 'tomato', 
                    'veg2' => 'carrot');

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays