PHP - How to count number of items in a list

PHP - How to count number of items in a list

Here is a way to sort a list by value and then print it out the count of duplicates.
$string = 'one, two, two, three, three, three, three, four, four, four, four, five, five, five, five, five';
$a = explode(',', $string );
$b = array_count_values($a);
arsort($b);
foreach ($b as $x => $x_value) {
    echo  $x;
    echo  $x_value;
}

Categories: Posts