Reputation: 95
I have an PHP Indexed array having only alphabet letters randomly i want to sort this array in ascending order and also want to avoid duplication. e.g.
$letters = array("b","d","g","h","v","a","c","a");
I want like this
$letters = array("a","b","c","d","g","h","v");
How I can perform this scenario specially ?
Upvotes: 1
Views: 1178
Reputation: 431
You can use sort function. Sort function accept parameter as array and sort it ascending order. Try the below code
$letters = array("b","d","g","h","v","a","c","a");
$letters = array_unique($letters);
sort($letters);
print_r($letters);
Upvotes: 0
Reputation: 11
Use sort()
to sort it, and array_unique()
to remove the duplicate values.
sort($letters);
$letters = array_unique($letters);
Upvotes: 1