计算数组中的值[重复]

This question already has an answer here:

Okay, this small problem is driving me insane.

This is the print_r output of $strap_materials:

Array(
    [0] => steel
    [1] => leather
    [2] => polyester
    [3] => leather
    [4] => steel 
)

I want to count how many times each value exists and put each sum in an array within an array, just like this:

Array(
    [0] => Array(
        "name"  => steel
        "count" => 2
    )
    [1] => Array(
        "name"  => leather
        "count" => 2
    )
    [0] => Array(
        "name"  => polyester
        "count" => 1
    )
)

My intention is to use the newly created array like this:

foreach($straps as $strap) {
    echo "Name: " . $strap->name;
    echo "Count: " . $strap->count;
}

How can I achieve that?

</div>

You can use array_count_values():

$counts = array_count_values($strap_materials);

foreach ($counts as $name => $count) {
    ...
}