You can flip the array, and check its length:
echo count(array_flip($arr));
This works because an array index must be unique, so you end up with one element for every unique item in the original array:
http://php.net/manual/en/function.array-flip.php
If a value has several occurrences, the latest key will be used as its value, and all others will be lost.
This is (was?) somewhat faster than array_unique
, but unless you are calling this a LOT, array_unique
is a lot more descriptive, so probably the better option
solved How to counting varians data from array?