Let $ item be the element whose frequency you are checking in the array, $ array the array you are looking for.
SOLUTION 1:
$array_count = array_count_values($array); if (array_key_exists($item, $array_count) && ($array_count["$item"] > 1)) { /* Execute code */ }
array_count_values โโ() returns an array using the values โโof the input array as keys and their frequency in the input as values โโ( http://php.net/manual/en/function.array-count-values.php )
SOLUTION 2:
if (count(array_keys($array, $item)) > 1) { }
Check http://www.php.net/manual/en/function.array-keys.php - "If the search_value option is specified, only keys for this value are returned"
Ninja source share