Reputation: 2307
I have the following array
$ar = array ( 1,2,3,4,5,3,6,7,...)
i do a foreach to display elements like
$i = 0
foreach ($ar as $tab){
echo $tab[i];
$i++
}
I dont want to display twice the same value like 3.
i just want 1 2 3 4 5 6 7...
Upvotes: 0
Views: 96
Reputation: 541
You may use flip-flip-merge technique which is faster than array_unique()
$ar = array(1,2,3,4,5,3,6,7);
$ar = array_merge(array_flip(array_flip($ar)));
You may read about it here http://thebatesreport.com/blog/?p=9
Upvotes: 0
Reputation: 94264
You can use array_unique
to get the unique set of values from your array before iterating over it:
$arr = array(1,2,3,4,5,3,6,7);
foreach (array_unique($arr) as $tab)
{
// ...
}
Upvotes: 4