note 58137 deleted from function.in-array by felipe
| From: | felipe@php.net | Date: | Sun, 30 Dec 2007 18:58:00 +0000 |
| Subject: | note 58137 deleted from function.in-array by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134486@lists.php.net to get a copy of this message | ||
Note Submitter: jpwaag at jpwaag dot com
----
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';
}
?>