2013-08-05 63 views
-2

我有這樣的功能:in_array始終返回false

function remove_addresse($input) { 
    if (!is_array ($input)) { 
     $input = array ($input); 
    } 

    foreach ($this -> message_meta['to_address'] as $key => $address) { 
     echo $address; 
     print_r($input); 
     if (in_array ($address, $input)) { 
      unset ($this -> message_meta['to_address'][$key]); 
     } 
    } 
} 

出於某種原因in_array總是返回false。

典型的$地址:[email protected]

典型的$輸入:Array ([0] => mult1.client.com [1] => mult3.client.com)

這究竟是爲什麼?

+5

你爲什麼期望這些匹配? ('@'與'。'不一樣) –

回答

0

除。是類型輸入中的拼寫錯誤,那麼針不在乾草堆中。

[email protected]!= mult3.client.com

+2

我是個白癡。這是顯而易見的 –

+0

Np。讓我們知道,問題是固定的還是僅僅是問題中的錯字? –

+0

我的測試數據中有拼寫錯誤 –

0

正如其他人所指出的,點不匹配@ -sign。 in_array()使用直接匹配,沒有正則表達式(因此沒有佔位符)。