This question already has an answer here:
- Counting values from an array 2 answers
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>