Your code already filters out all duplicates. If you would like case-insensitivity you can use this function
function array_iunique($array) {
return array_intersect_key(
$array,
array_unique(array_map("StrToLower",$array))
);
}
(Found this gem on Stackoverflow[
^].)
Use this function in your code and change the "Orange" in the $veggies to "orange".
$veggies = array("Potato", "Cucumber", "Carrot", "orange", "Green Beans", "Onion");
$fruits = array("Apple", "Banana", "Orange", "Pineapple", "Grapes", "Watermelon");
$salad = array_iunique(array_merge($veggies ,$fruits));
print_r($salad);
This outputs to
Array
(
[0] => Potato
[1] => Cucumber
[2] => Carrot
[3] => orange
[4] => Green Beans
[5] => Onion
[6] => Apple
[7] => Banana
[9] => Pineapple
[10] => Grapes
[11] => Watermelon
)
The Orange appears only once in the result.