PHP array_intersect或in_array那么MySQL [英] PHP array_intersect or in_array then 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屋!