I found a few solutions but I can't decide which one to use. What is the most compact and effective solution to use php's array_unique()
function on a case-insensitive array?
Example:
$input = array('green', 'Green', 'blue', 'yellow', 'blue');
$result = array_unique($input);
print_r($result);
Result:
Array ( [0] => green [1] => Green [2] => blue [3] => yellow )
How do we remove the duplicate green
? As far as which one to remove, we assume that duplicates with uppercase characters are correct.
e.g. keep PHP
remove php
or keep PHP
remove Php
as PHP
has more uppercase characters.
So the result will be
Array ( [0] => Green [1] => blue [2] => yellow )
Notice that the Green with uppercase has been preserved.
trim()
the values as well, but that's up to OP's definition of duplicate. – Gigigigli