DEV Community

loading...

Discussion on: Daily Challenge #273 - Remove Duplicates

Collapse
peter279k profile image
peter279k

Here is the simple solution with PHP:

function solve($arr) {
  $ansArr = [];

  $index = count($arr)-1;
  for(; $index >= 0; $index--) {
    if (in_array($arr[$index], $ansArr) == false) {
      $ansArr[] = $arr[$index];
    }
  }

  return array_reverse($ansArr);
}