我会将您的字符串拆分为一个数组,然后将其与要匹配的元素数组进行比较.
$originalList = explode('_', 'a_b_c');
$matchList = array('a', 'b', 'c');
$diff = array_diff($matchList, $originalList);
if (!empty($diff)) {
// At least one of the elements in $matchList is not in $originalList
}
Run Code Online (Sandbox Code Playgroud)
请注意重复元素和不重复元素,具体取决于数据的来源.
文档: