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;
}
?>
----
Server IP: 217.13.201.10
Probable Submitter: 134.102.230.241
----
Manual Page -- ht
tp://www.php.net/manual/en/function.is-array.php
Edit -- https://master
.php.net/note/edit/76055
Del: integrated -- h
ttps://master.php.net/note/delete/76055/integrated
Del: useless -- http
s://master.php.net/note/delete/76055/useless
Del: bad code -- htt
ps://master.php.net/note/delete/76055/bad+code
Del: spam -- https:/
/master.php.net/note/delete/76055/spam
Del: non-english --
https://master.php.net/note/delete/76055/non-english
Del: in docs -- http
s://master.php.net/note/delete/76055/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/76055
Reject -- https://mast
er.php.net/note/reject/76055
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|