note 76188 deleted from function.is-array by tularis

From: Date: Sun, 09 Oct 2011 09:28:34 +0000
Subject: note 76188 deleted from function.is-array by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183742@lists.php.net to get a copy of this message
Note Submitter: Rob ---- Here's another way to see if an array is associative (nobody actually uses the term "vector" ;-) ). It's a little less breakable than the other current leading suggestion, and it's somewhat faster. Tested with 1000 iterations of two simple arrays (one associative, one not). <?php function array_is_associative ($array) { if ( is_array($array) && ! empty($array) ) { for ( $iterator = count($array) - 1; $iterator; $iterator-- ) { if ( ! array_key_exists($iterator, $array) ) { return true; } } return ! array_key_exists(0, $array); } return false; } ?>

« previous php.notes (#183742) next »