Reputation: 75
<?php
$array = array('aaa', 'bbb', 'aaa', 'ccc', 'ddd', 'ccc', 'eee');
foreach($array as $a){
echo $a;
}
Is possible use some like DISTINCT for foreach? I would like show each values only one, without repeat. How is the best way for this?
Upvotes: 0
Views: 583
Reputation: 58444
Actually array_unique()
gets pretty bad when you have large arrays. You would be better off with $uniques = array_flip(array_flip($array))
.
Upvotes: 1
Reputation: 78971
Use array_unique()
$array = array('aaa', 'bbb', 'aaa', 'ccc', 'ddd', 'ccc', 'eee');
$result = array_unique($array);
print_r($result);
Upvotes: 10