Php strrpos未检测到字符串,始终为0位置

Php strrpos未检测到字符串,始终为0位置,php,string,foreach,strpos,Php,String,Foreach,Strpos,嗨,伙计们,这真是令人震惊的问题 我有很多使用strrpos的经验,但这实在是不合情理。首先是阵列: arrCopy => { ["Codice"]=> string(33) "Per sport d è numerico" ["Maniche"]=> string(15) " maniche corte "

嗨,伙计们,这真是令人震惊的问题

我有很多使用strrpos的经验,但这实在是不合情理。首先是阵列:

arrCopy => {                
  ["Codice"]=>                
  string(33) "Per sport d è numerico"                
  ["Maniche"]=>                
  string(15) " maniche corte "                
  ...               
  ["Taglia"]=>                
  string(8) "tg tg XL"                
}
我想在Foreach循环中隔离“Taglia”的行为,但我无法检测到它

foreach ($arrCopy as $key=>$spec){
         echo gettype($key); // prints string
         $tg= strpos(strtolower($key) , 'taglia'); // gives me 
//always 0 also with "Taglia" key
            if (  $tg !== false || ....
                 // never goes there

我错在哪里

您应该测试strpos()的retval是否为FALSE,以确定是否包含该字符串

发件人:

此函数可能返回布尔值FALSE,但也可能返回计算结果为FALSE的非布尔值,例如0或“”。有关更多信息,请阅读布尔值部分。使用===运算符测试此函数的返回值


可能最好使用strcmp-您并不是为了寻找子字符串,而是为了确保匹配。

我像您所说的那样使用了运算符请检查我是否已写入($tg!==发现了错误问题反正我对if语句有错误,很抱歉打扰您