gpt4 book ai didi

php - 比较两个数组,如果数组匹配则返回 id

转载 作者:行者123 更新时间:2023-11-29 11:36:55 25 4
gpt4 key购买 nike

我在 codeigniter 工作。我有两个表 job_post 和 snapshot。我已经编写了查询来从上面的表中获取数据,例如:

查询1:

select skill from snapshot where user_id = 1

它给出了像这样的数组:

Array
(
[0] => stdClass Object
(
[skill] => 1,2
)
)

查询2:

select emp_id,skill from job_post

这个查询返回如下数组:

Array
(
[0] => stdClass Object
(
[emp_id] => 10
[skill] => 1,2,3
)

[1] => stdClass Object
(
[emp_id] => 10
[skill] => 3,12,13
)
)

现在,我想将它们与数组匹配。如果 query1 技能与 query2 技能匹配,则返回 emp_id。那么我怎样才能获得 emp_id 呢?

注意:与query1和query2的部分匹配

最佳答案

将以下查询的响应存储在变量中(例如 $mySkill 中)。

select skill from snapshot where user_id = 1;

"select emp_id,skill from job_post where concat(',',skill,',') like '%,".$mySkill.",%'"

替代方案:您需要分解 $myskill 然后需要动态创建或条件。例如:

$arrmyskill = explode(",",$mySkill); 
foreach($arrmyskill as $skill )
{
$str .=" or concat(',',skill,',') like '%,".$skill.",%' ";
}
$finalqry = "select emp_id,skill from job_post where concat(',',skill,',') like '%".$mySkill."%'" .$str;

关于php - 比较两个数组,如果数组匹配则返回 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36426018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com