note 76188 added to function.is-array

From: Date: Wed, 04 Jul 2007 08:04:58 +0000
Subject: note 76188 added to function.is-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-128220@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 69.105.90.102 ---- Manual Page -- http://www.php.net/manual/en/function.is-array.php Edit -- https://master.php.net/note/edit/76188 Del: integrated -- https://master.php.net/note/delete/76188/integrated Del: useless -- https://master.php.net/note/delete/76188/useless Del: bad code -- https://master.php.net/note/delete/76188/bad+code Del: spam -- https://master.php.net/note/delete/76188/spam Del: non-english -- https://master.php.net/note/delete/76188/non-english Del: in docs -- https://master.php.net/note/delete/76188/in+docs Del: other reasons-- https://master.php.net/note/delete/76188 Reject -- https://master.php.net/note/reject/76188 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128220) next »