<?php
$array = array('title1','title2','title2','title3','title4','title5','title5','title6','title6','title5');
sort($array);
$unique_length = count( array_unique($array) );
$total_dupes = 0;
$clean = array();
for ($i=0; $i<$unique_length; $i++) {
$current = array_shift($array);
if ($current === NULL)//already have all elements
break;
$found = 1;
while (($key = array_search($current, $array)) !== FALSE) {//search for dupes
$found++;
unset($array[$key]);
}
if ($found == 1)
array_push($clean, $current);
else {
$dupes = array();
for ($i=0; $i<$found; $i++)
$dupes[] = $current;
$total_dupes++;
$clean['dupe'.$total_dupes] = $dupes;
}
}
print_r($clean);
preferences:
46.84 ms | 402 KiB | 5 Q