note 107721 added to function.in-array
| From: | janis dot janovskis at gmail dot com | Date: | Tue, 28 Feb 2012 23:03:30 +0000 |
| Subject: | note 107721 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186422@lists.php.net to get a copy of this message | ||
Since sometimes in_array returns strange results - see notes above.
I was able to find value in array by this quite a simple function;
<?php
/**
* $find <mixed> value to find
* $array<array> array to search in
*/
function _value_in_array($array, $find){
$exists = FALSE;
if(!is_array($array)){
return;
}
foreach ($array as $key => $value) {
if($find == $value){
$exists = TRUE;
}
}
return $exists;
}
// Note
// You can't use wildcards and it does not check variable type
?>
----
Server IP: 69.147.83.197
Probable Submitter: 109.157.181.168
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit -- https://master.php.net/note/edit/107721
Del: integrated -- https://master.php.net/note/delete/107721/integrated
Del: useless -- https://master.php.net/note/delete/107721/useless
Del: bad code -- https://master.php.net/note/delete/107721/bad+code
Del: spam -- https://master.php.net/note/delete/107721/spam
Del: non-english -- https://master.php.net/note/delete/107721/non-english
Del: in docs -- https://master.php.net/note/delete/107721/in+docs
Del: other reasons-- https://master.php.net/note/delete/107721
Reject -- https://master.php.net/note/reject/107721
Search -- https://master.php.net/manage/user-notes.php