$valid = array('a', 'b');
$invalid = array('a', 'd');
$arrays = array(
'1' => array('a', 'b', 'c'),
'2' => array('d', 'e', 'f'),
'3' => array('g', 'h', 'i'),
);
foreach ($valid as $input) {
$inArray = array();
foreach ($arrays as $key => $array)
if (in_array($input, $array))
$inArray[] = $key;
}
foreach ($invalid as $input) {
$numberOfArrays = array();
foreach ($arrays as $key => $array)
if (in_array($input, $array))
$inArray[] = $key;
}
$inArray
你可以用ie的长度来证明
if (length($inArray) === 1) {
echo 'Valid';
} else {
echo 'Invalid';
}
编辑:
并证明所有值是否来自一个数组:
if ((length($inArray) === 1) and (length($valid) === length($arrays['1']))) {
echo 'Valid';
} else {
echo 'Invalid';
}