php - 将内爆数据与另一个内爆进行匹配

标签 php mysql match implode

我有来自两个不同表的数据,这些数据在从复选框中选择后已经内爆,并且它们被“,”分隔。当我从数据库中选择它们后,这两个变量可能如下所示。

$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/

相关文章:

php - 评论删除按钮不起作用

php - 在 PHP 中针对数组选择的表单

php - 正则表达式 PHP 拆分数字和字符串

jquery - 尝试使用与 window.location.pathname 匹配的模式

php - ip2long 转换后的 IP 应该如何存储在 MySQL 中?

php - 从运行 PHP 的应用服务调用 Azure 表存储时出现 cURL 错误 60

PHP mysql连接?

mysql - 如何从 Mysql Workbench 创建 CHECK 约束

shell - 使用 sed 找到匹配项时替换整行

php - url.rewrite-once 与 Kohana 和 urls