PHP array_intersect或in_array那么MySQL [英] PHP array_intersect or in_array then MYSQL

查看:97
本文介绍了PHP array_intersect或in_array那么MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要找到,如果两个数组匹配,然后在那里他们从他们匹配的mysql匹配一行提取数据。我应该使用

  $ SQL =SELECT * FROM围绕;
 $ resultsd = $ conn->查询($的SQL);
 的foreach($ resultsd如rowd $){} 如果(array_intersect($ AR1,$ AR2)){
    $剑[] = $ rowd ['TIM'];
    }

或者我应该用

 如果(in_array($ AR1,AR2 $)){
       $剑[] = $ rowd ['TIM'];
   }

获取阵列,如:

  $ AR1 [] = $ rowd [净息差'];
   $ AR2 [] = $ rowd [净息差'];

那么一个人如何去拉动特定行,他们在匹配?

我看到它们匹配,并打印出数组的好:

 阵列([0] => dcbabcbded)阵列([0] => fafeafaebee [1] => afabfdefcbb [2] => dcbabcbded

但是,当我尝试了回音,他们符合我失败了MySQL的数据:

 阵列()


解决方案

使用 $新= array_intersect(阵列([0] => dcbabcbded),阵列([0] => fafeafaebee [ 1] => afabfdefcbb [2] => dcbabcbded)):然后进行有效的SQL如上面我的回答说。

如果妳确保你已经拥有百达阵intersenct有一个或没有值,则使SQL只是一个数组元素: $ AR [0] 使用SQL WHERE 子句。

Need to find if two arrays match, and then where they match pull data from the mysql row in which they match. Should I use

 $sql = "SELECT * FROM around";
 $resultsd = $conn->query($sql);
 foreach($resultsd as $rowd) {}

 if (array_intersect($ar1, $ar2)) {
    $sword[] = $rowd['TIM'];
    }

or should I use

 if (in_array($ar1, $ar2)) {
       $sword[] = $rowd['TIM'];
   }

Getting the arrays like:

   $ar1[] = $rowd['nim']; 
   $ar2[] = $rowd['nim']; 

Then how does one go about pulling the specific row that they match at?

I am seeing that they match, and printing out the array's okay:

Array ( [0] => dcbabcbded ) Array ( [0] => fafeafaebee [1] => afabfdefcbb [2] => dcbabcbded

But when I trying a echo the mysql data where they match I fail:

 Array ( )  

解决方案

use $new = array_intersect(Array ( [0] => dcbabcbded ), Array ( [0] => fafeafaebee [1] => afabfdefcbb [2] => dcbabcbded)) : then make valid sql as stated in my answer above.

If u are sure you've allways have array intersenct with one or none values, then make sql just with first array element: $ar[0] using sql WHERE clause.

这篇关于PHP array_intersect或in_array那么MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆