How to see foreach output after array_unique?

This is the code

$array = array("Raj", "Amit", "Rahul", "Amit", "Chandra", "Kishore", "Chandra");
foreach ($array as $key => $names) {
    echo ($key . " => " . $names . "<br/>");
}
$result = array_unique($array);
var_dump($result);

Instead of removing the duplicate items, I am getting the original array items. How can I run the array through foreach to see the output after removing the item?

You are using array_unique _after the foreach.
Put it before.

2 Likes

Does the var_dump() show the correct information? If it does, then as above, just use the foreach() on $result after you’ve called the function.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.