3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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);
Output for 4.3.0 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
Array ( [0] => title1 [dupe1] => Array ( [0] => title2 [1] => title2 ) [1] => title3 [2] => title4 [dupe2] => Array ( [0] => title5 [1] => title5 [2] => title5 ) [dupe3] => Array ( [0] => title6 [1] => title6 ) )
Output for hhvm-3.10.0

Process exited with code 153.