note 76055 deleted from function.is-array by tularis

From: Date: Sun, 09 Oct 2011 09:28:06 +0000
Subject: note 76055 deleted from function.is-array by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183741@lists.php.net to get a copy of this message
Note Submitter: markus-rehrs at gmx dot de ---- @elanthis at awesomeplay dot com, your function to check whether an array is a map or a vector has a little flaw. Comparing $k != $value will return true if $value is 0. If you check a map containing just one element like array('foo'=>'bar') your check assumes that this is a vector. Use the operator !== (not identical with) to avoid that: <?php function is_vector (&$array) { $next = 0; foreach ($array as $k=>$v) { if ($k !== $next) return false; $next++; } return true; } ?>

« previous php.notes (#183741) next »