You can use this code and I hope it will help you. It's completely working:
$array = array(1,1,2,3,4,4,4,5);
$temp=array();
for($i=0; $i<=count($array); $i++)
{
if($array[$i] != '')
{
for($j=$i+1; $j<=count($array); $j++ )
{
if($array[$i]==$array[$j])
{
$array[$j] = '';
}
else
{
$temp[$array[$i]]=$array[$i];
}
}
}
}
print_r($temp);