我有来自两个不同表的数据,这些数据在从复选框中选择后已经内爆,并且它们被“,”分隔。当我从数据库中选择它们后,这两个变量可能如下所示。
$firstvar = Red, Blue, Green, Yellow
$secondvar = Green, Purple, White
所以我想知道当两个变量中至少有一种颜色匹配时,我如何检查是否存在匹配。
我一直在尝试:
if (strpos($firstvar , $firstvar ) !== false) {
echo 'There is a match';
}
但是这不起作用。
最佳答案
从数据库获取结果后,分解这两个变量:
就像这样:
$firstvar = explode(",",$firstvar);
$secondvar = explode(",",$secondvar );
现在,使用这个函数:
$match = array_intersect($firstvar,$secondvar);
现在,内爆结果输出:
$result = implode(",",$match);
echo $result;
希望这对您有用。
关于php - 将内爆数据与另一个内爆进行匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42205594/