Sort an Array of Strings Alphabetically in PHP
The below code example shows you how to sort a PHP array of strings alphabetically using sort()
function.
example.php
<?php
$users = array(
'Obama',
'Dan',
'Andrew',
'David',
'Michelle'
);
// sort the array
sort($users);
// result
var_dump($users);
Output:
array(5) {
[0]=>
string(6) "Andrew"
[1]=>
string(3) "Dan"
[2]=>
string(5) "David"
[3]=>
string(8) "Michelle"
[4]=>
string(5) "Obama"
}