How do i count same values in an array and store it to a variable?

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

Leave a Comment