Php 对照其他不同大小的数组值检查数组值
我有一个脚本,考虑过使用array_intersect,但发现如果数组大小不同,它显然不会检查所有数组值 在我的例子中,我必须对照两个数组检查URL的部分,一个带有域名,另一个带有特定字符串:Php 对照其他不同大小的数组值检查数组值,php,arrays,Php,Arrays,我有一个脚本,考虑过使用array_intersect,但发现如果数组大小不同,它显然不会检查所有数组值 在我的例子中,我必须对照两个数组检查URL的部分,一个带有域名,另一个带有特定字符串: <?php $confirm_ref = "http://www.example.com/?x=test&test"; $pp_refz = array_filter(preg_split('(https://|http://|www.|&|=|/|-|\?)', $confirm_
<?php
$confirm_ref = "http://www.example.com/?x=test&test";
$pp_refz = array_filter(preg_split('(https://|http://|www.|&|=|/|-|\?)', $confirm_ref));
$domains = array("bla.com","bla1.net","bla2.com","bla3.com","bla4.tk","blabla.com","blabla1.com","blabla3.net","example.com");
$strings = array("DIg","AsD","w5L","ptp","ptp.php","hps.php","hide.php","p");
print_r(array_values($pp_refz));
//Check function:
if(array_intersect($pp_refz,$domains,$strings) == true) {
echo "gotcha";
}
?>
即使example.com存在于引用数组($pp_refz)中,它仍然没有被提取。这个问题是否有任何可能的解决方法?还是我在这里遗漏了什么?任何指点都将不胜感激。谢谢。好的,我想我试着将两个数组合并成一个,然后只比较剩下的两个数组: 这是最终的工作版本:
<?php
$confirm_ref = "http://www.example.com/?x=test&test";
$pp_refz = array_filter(preg_split('(https://|http://|www.|&|=|/|-|\?)', $confirm_ref));
$domains = array("bla.com","bla1.net","bla2.com","bla3.com","bla4.tk","blabla.com","blabla1.com","blabla3.net","example.com");
$strings = array("DIg","AsD","w5L","ptp","ptp.php","hps.php","hide.php","p");
//print_r(array_values($pp_refz));
$big = array_merge($domains, $strings);
//print_r(array_values($big));
//Check function:
if(array_intersect($pp_refz,$big) == true) {
echo "gotcha";
}
?>
也许有人可以解释为什么它在与多个数组进行比较时不起作用。您能看到这一行的输出吗
print\r(array\u values($pp\u refz))代码>?确定:Array([0]=>example.com[1]=>x[2]=>test[3]=>test)Array_intersect()返回一个数组,该数组包含所有参数中存在的array1的所有值。这里三个数组中不存在公共值。因此条件变为false。$domains数组中存在“example.com”……是的,但它在$string数组中不存在(array_intersect($pp_refz,$domains,$strings)==true)“这三者的交集返回false