note 62225 deleted from function.is-array by tularis

From: Date: Sun, 09 Oct 2011 09:25:14 +0000
Subject: note 62225 deleted from function.is-array by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183737@lists.php.net to get a copy of this message
Note Submitter: mot4h at cs dot virginia dot edu ---- I was looking at several of the other examples for testing if an array is associative and they seemed a little limited, or a little bulky. Here's my take on it, I think it's a nice balance: <?php function is_associative($array){ if (!is_array($array)) return false; foreach(array_keys($array) as $key=>$value) { if ($key != $value) return true; } return false; } ?> The idea being that the array_keys() function returns a non-associative array, so if the array you fed it wasn't associative, all the key/value pairs in the array of keys should be identical. Otherwise it must have been associative.

« previous php.notes (#183737) next »