Is there a PHP code snippet or a built in array function that would do kind of like what a sql statement with having and group by does? That is removing the dups and counting the occurrences and giving you back an array that you can use for reporting/debugging purposes.
An example may clarify;
say your array is like this
Array (
['0'] => usa
['1'] => minnesota
['2'] => california
['3'] => san fransisco
['4'] => los angeles
['5'] => san fransisco
['6'] => malibu
['7'] => malibu
['8'] => malibu
['9'] => usa
}
and you want something back like this, or something to this effect..
Array (
['usa'] => 2
['minnesota'] => 1
['california'] => 1
['san fransisco'] => 2
['los angeles'] => 1
['malibu'] => 3
}
http://www.php.net/manual/en/function.array-count-values.php
You can use the following code to do this:
array_count_values ($myArray)
Doing it manually:
$new = array();
foreach($array as $key => $val) {
if (!isset($new[$key]) {
$new[$key] = 0;
}
$new[$key]++;
}
Use array_count_values()
to get the number of duplicates
$array = array(...);
$duplicate = array_count_values($array);