$text = "Wyse Dell WYSE";
$words = array_unique(explode(' ',$text));
$words = implode(' ',$words);
echo $words;
// output: Wyse dell WYSE这个解决方案可以区分大小写,并立即重复单词,但并不总是像上面的例子那样。我需要它来做一个对案件不敏感的搜索。
发布于 2015-02-28 08:24:07
$text = "Wyse Dell WYSE";
$words = array_iunique(explode(' ',$text));
$words = implode(' ',$words);
echo $words;
function array_iunique($array) {
return array_intersect_key(
$array,
array_unique(array_map("StrToLower",$array))
);
}来源:unique
array_map将strtolower应用于所有值,并返回所有值大小写的数组,array_unique从array_map返回中删除所有重复项。array_intersect_key返回一个数组,该数组包含$array的所有条目,这些条目都有返回array_unique的键。有关功能的更多详细信息:
array_map:http://php.net/manual/en/function.array-map.php
array_intersect_key:http://php.net/manual/en/function.array-intersect-key.php
strtolower:http://php.net/strtolower
发布于 2015-02-28 08:23:01
试试这样的东西。
$text = "Wyse Dell WYSE";
$words = array_unique(explode(' ',strtolower($text)));
$words = implode(' ',$words);
echo $words;https://stackoverflow.com/questions/28779616
复制相似问题