$items = explode(\',\',$product); // values is 4,2,4,2,2,4
$unique_items=array_unique($items); // gives me 4,2
What code should be next to give me
see: array_count_values
Like:
$occurences = array_count_values($items);
print_r($occurences);
Output:
Array
(
[4] => 3
[2] => 3
)
Usage:
echo $occurences[4]; // outputs 3
You're probably looking for array_count_values() function.
check here : array_count_values() https://www.w3schools.com/php/showphp.asp?filename=demo_func_array_count_values