Php 数组内多维数组搜索

Php 数组内多维数组搜索,php,Php,首先,我有一个多维数组,如下所示: $array=array (0 => array (0 => '',),1 => array (0 => 'sample.com',1 => 'test.com',2 => 'check.com',3 =>'rack.com',),2 => array (0 => '12345.34535',1 => '243.345345.4535',2 => '3453.534534',3 =>

首先,我有一个多维数组,如下所示:

$array=array (0 => array (0 => '',),1 => array (0 => 'sample.com',1 => 'test.com',2 =>    'check.com',3 =>'rack.com',),2 => array (0 => '12345.34535',1 => '243.345345.4535',2 => '3453.534534',3 => '45.453453',),3 => array (0 => '978.797',1 => '789.7897997.7897',2 => '97897.78979.798',3 => '78978979',),4 => NULL,5 => NULL,6 => NULL,7 => NULL,8 => NULL,9 => NULL,10 => NULL,11 => NULL,12 => NULL,);
我有用户在变量中选择的选项:

$options=array (0 => 'blreferrer',1 => 'ipwl',2 => 'ipbl',);
我使用下面的代码从用户选择的多维数组中获取正确的键

$options1 = array(0=>"wlreferrer",1=>"blreferrer",2=>"ipwl",3=>"ipbl",4=>"geowl",5=>"geobl",6=>"languagewl",7=>"languagebl",8=>"browserwl",9=>"browserbl",10=>"oswl",11=>"osbl",12=>"viscount");

$option2 = (array_intersect($options1, $options));

$option3 = (array_keys($option2));  
下面的代码用于搜索第一个多维数组

$option4 = array();

$referrer = 'sample.com';

$ip = '789.7897997.7897';

$option5 = array(0=>$referrer,1=>$referrer,2=>$ip,3=>$ip,4=>$geo,5=>$geo,6=>$language,7=>$language,8=>$browser,9=>$browser,10=>$os,11=>$os,12=>$viscount);
最后我试着搜索

foreach ($option3 as $key) {

if (in_array($option5[$key], $array[$key])) {

array_push($option4, "0");

} else {

array_push($option4, "1");

}

}
当我打印$option4时,当它应该为0,1,0时,我得到以下结果

 Array ( [0] => 1 [1] => 1 [2] => 1 )

我相信问题源于在多维数组上使用in_数组,但尚未找到任何解决方案。

您可以使用数组过滤器进行此搜索。例如:

$example_array = [your array];
$reference_array = [the values to be searched];

$filtered = array_filter($example_array,function($element)use($reference_array){
    foreach($element as $index=>$value){
        if(in_array($value,$reference_array)){
            return true;
        }
    }
});

你能再解释一下你想解决的最初问题吗?根据什么标准输出应该是0,1,0?例如$array[1]包含一个referer列表,我想检查referer$referer的数组。