note 86658 added to function.is-array
| From: | jim at akubo dot net | Date: | Tue, 28 Oct 2008 19:02:12 +0000 |
| Subject: | note 86658 added to function.is-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-145898@lists.php.net to get a copy of this message | ||
yousef's example was wrong because is_vector returned true instead of false if the key was
found
here is the fixed version (only 2 lines differ)
<?php
function is_vector( &$array ) {
if ( !is_array($array) || empty($array) ) {
return -1;
}
$next = 0;
foreach ( $array as $k => $v ) {
if ( $k !== $next ) return false;
$next++;
}
return true;
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 68.55.100.7
----
Manual Page -- http://www.php.net/manual/en/function.is-array.php
Edit -- https://master.php.net/note/edit/86658
Del: integrated -- https://master.php.net/note/delete/86658/integrated
Del: useless -- https://master.php.net/note/delete/86658/useless
Del: bad code -- https://master.php.net/note/delete/86658/bad+code
Del: spam -- https://master.php.net/note/delete/86658/spam
Del: non-english -- https://master.php.net/note/delete/86658/non-english
Del: in docs -- https://master.php.net/note/delete/86658/in+docs
Del: other reasons-- https://master.php.net/note/delete/86658
Reject -- https://master.php.net/note/reject/86658
Search -- https://master.php.net/manage/user-notes.php