0

I have array Array ( [0] => 1,2,3,4,5 [1] => 1,2 [2] => 1,2 )

how to remove duplicate elements and i want to single array like

Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5)

2
Contributors
2
Replies
16
Views
2 Years
Discussion Span
Last Post by ramsiva
1

Well, key 1 and 2 are duplicates, not key 0.
You're not really removing duplicates from the example you have given of what you're wanting, you're changing the values of the array.

It's almost like you want to implode the array with comma delimiter, then explode the array on commas, and then remove all duplicates.
If that is what you're after, that could be done like this

array_unique(explode(",", implode(",", $array)));
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.