Procure valores duplicados em uma matriz associativa e adicione-os a uma contagem
Oi eu estou tentando contar o número de valores duplicados em uma matriz associativa que se parece com isso:
array(3) { [0]=> array(3) { ["Title"]=> string(25) "hello"
["Price"]=> int(50)
["Count"]=> int(1) }
[1]=> array(3) { ["Title"]=> string(35) "world"
["Price"]=> int(50)
["Count"]=> int(1) }
[2]=> array(3) { ["Title"]=> string(25) "hello"
["Price"]=> int(50)
["Count"]=> int(1) } }
Como você pode ver aqui, há um valor duplicado na lista "Title". Eu quero contá-los e adicionar um à parte "Count". Eu comecei a fazer algo assim:
$prodArray = array();
// Add the values to the array if it's the first time it occurs.
if (!in_array($row['prodTitle'], $prodArray["Title"]))
{
array_push($prodArray,
array( Title => $row['prodTitle'],
Price => $row['prodPrice'],
Count => 1)
);
}
else
{
//Add one to the count for the current item.
}
A coisa é que eu não posso acessar o elemento "Título" na matriz através da função in_array. Todas as sugestões são bem vindas.