1
首先我有一個多維數組,如下所示:in_array多維數組搜索
$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));
下面的代碼是util美化版用於搜索第一多維數組
$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");
}
}
當我打印出$ 3選項,我得到下面的結果時,它應該是0,1,0 ..
Array ([0] => 1 [1] => 1 [2] => 1)
我認爲這個問題源於在多維數組上使用in_array,但是一直沒能找到任何解決方案。
你能解釋一下你最初想解決的問題嗎?根據什麼標準輸出爲0,1,0? – deceze 2012-04-02 02:21:12
例如$ array [1]包含一個引用列表,我想檢查引用$引用的數組。 – user1304713 2012-04-02 02:25:46