如何搜索唯一数组值保留原始值并通过“&nbsp”更改其余值

I need to search the first unique value and change the succeeding value by space. how can I do it? I just need it in listing report without duplicating display of the values.

$array = array("a", "a", "a", "b", "b", "b", "b");

how to find "a" and change the suceeding a by "&nbsp"
how to find "b" and change the suceeding b by "&nbsp"

OUTPUT: $array = array("a", "&nbsp", "&nbsp", "b", "&nbsp", "&nbsp", "&nbsp");

Thank you.

I'm sure there has to be a better way, but in the meantime:

$array = array("a", "a", "a", "b", "b", "b", "b");

$result=array();

foreach ($array as $value) {
  if (! in_array($value, $result)) {
    array_push($result,$value);
  } else {
    array_push($result,"&nbsp");
  }
}

print_r($result);

This will get you something like an "array_unique" but replacing all repeated values with "&nbsp" no matter the order of the values.

edit: If you need a function that replaces the original array you can use this:

$array = array("a", "a", "a", "c", "b", "b", "b", "b","c");

function array_replace_repeat(&$array) {
  $tmpArr=$array;
  $array=array();
  foreach ($tmpArr as $value) {
    if (! in_array($value, $array)) {
      array_push($array,$value);
    } else {
      array_push($array,"&nbsp");
    }
  }
}

array_replace_repeat($array);