array_count_values < PHP

The array_count_values function counts the number of elements in an array and returns an associative array of how many times each element appears in the array.

    
    $cars = array("Ford","Honda","Chrysler","Ford","Cadillac","Cadillac","Cadillac");

    $carsCount = array_count_values($cars);

    print_r($carsCount);
    // Array
    // (
    //     [Ford] => 2
    //     [Honda] => 1
    //     [Chrysler] => 1
    //     [Cadillac] => 3
    // )