Given array like this:
$products = array([0] => Apple, [1] => Orange, [2] => Orange, [3] => Strawberry, [4] => Orange, [5] => Mango, [6] => Orange, [7] => Strawberry, [8] => Orange, [9] => Orange, [10] => Orange);
I need to count number of similar values and receive array where each unique value will appear once along with the count of its occurrences from original array. For example the new array should look like this:
$new_products = array([0] => "Apple 1", [1] => "Orange 7", [2] => "Strawberry 2", [3] => "Mango 1");
Using functions below I can receive 2 arrays:
array_keys(array_count_values($products))); // Return array of unique values
array_values(array_count_values($products))); // Return array with count for each unique values
Will return:
Array ( [0] => Apple 1 [1] => Orange [2] => Strawberry [3] => Mango )
Array ( [0] => 1 [1] => 7 [2] => 2 [3] => 1 )
I cant find a way to merge the values so I get the array that looks like $new_products array in my example.