我对不敏感的 array_keys 和 in_array 有疑问......我正在开发一个翻译器,我有这样的事情:
$wordsExample = array("example1","example2","example3","August","example4");
$translateExample = array("ejemplo1","ejemplo2","ejemplo3","Agosto","ejemplo4");
function foo($string,$strict=FALSE)
{
$key = array_keys($wordsExample,$string,$strict);
if(!empty($key))
return $translateExample[$key[0]];
return false;
}
echo foo('example1'); // works, prints "ejemplo1"
echo foo('august'); // doesnt works, prints FALSE
我用 in_array 进行了测试,结果相同......:
function foo($string,$strict=FALSE)
{
if(in_array($string,$wordsExample,$strict))
return "WOHOOOOO";
return false;
}
echo foo('example1'); //works , prints "WOHOOOOO"
echo foo('august'); //doesnt works, prints FALSE