Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能是一个已经讨论过的话题,但在 PHP 中我没有找到答案是否有更简单的方法来实现以下内容:
$a = array("hello","hello","Hello","world","worlD"); $p=array(); foreach( $a as $v ){ $p[strtolower($v)] = ""; } print_r($p);
在小情况下为数组保留一个元素
就像是:
$p = array_unique(array_map('strtolower', $a));
您可以使用array_flip交换键和值:
array_flip
$a = array_flip(array_map('strtolower', $a));