note 93433 deleted from function.is-array by danbrown
| From: | danbrown@php.net | Date: | Wed, 09 Sep 2009 23:18:37 +0000 |
| Subject: | note 93433 deleted from function.is-array by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-160374@lists.php.net to get a copy of this message | ||
Note Submitter: IpSo
----
This is the fastest way I've come across to determine if an array is associative or purely
numerically keyed. It runs between 2x and 3x faster than any other method I've found in the
comments.
Either way its pretty slow on large arrays, in the 30ms range for 100,000 elements. Other methods
were in the 100-150ms range.
function is_assoc( $array ) {
$i=0;
foreach($array as $k=>$v) {
if ( $k !== $i OR (int)$k !== $k ) {
return TRUE;
}
$i++;
}
return FALSE;
}