note 58137 added to function.in-array
| From: | jpwaag at jpwaag dot com | Date: | Tue, 25 Oct 2005 12:51:39 +0000 |
| Subject: | note 58137 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-97571@lists.php.net to get a copy of this message | ||
In case you want to check if multiple values are in your array, you can use this function:
<?php
function array_values_in_array($needles, $haystack) {
if(is_array($needles)){
$valid=true;
foreach($needles as $needle){
if(!in_array($needle, $haystack)){
$valid=false;
}
}
return $valid;
}else{
return in_array($needles, $haystack);
}
}
//for example
$needles=array('ubuntu', 'gentoo', 'suse');
$haystack=array('ubuntu', 'gentoo', 'suse', 'knoppix',
'fedora', 'debian');
if(array_values_in_array($needles, $haystack)){
echo 'All the values of $needles are in $haystack';
}else{
echo 'Some values of $needles are not in $haystack';
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+58137
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58137&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58137&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58137&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58137&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58137&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58137&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58137&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+58137&report=yes
Search -- http://master.php.net/manage/user-notes.php