php爆炸后按字母顺序输出

i have a string like

 $email= "yun@hotmail.com,sibel@hotmail.com,yusufsar@hotmail.com";

first i explode this like

 $wordChunks = explode(",", $email);
for($i = 0; $i < count($wordChunks); $i++){

$eex = mysqli_query($database->connection,"SELECT * FROM contacts where email =   '$wordChunks[$i]' and owner = '$session->username'") or die(mysqli_error());
    while($zzz = mysqli_fetch_array($eex)){


     if(empty($zzz['bedrijfsnaam'])){
        $aa = "<font size='2'>".ucfirst($zzz['name'])." ".ucfirst($zzz['lastname'])."</font>";
    }else{
     $aa = "<font size='2'>".ucfirst($zzz['bedrijfsnaam'])."</font>";
    }
    echo $aa;

     }
}

The question is how can i order $aa in alphabetic order

What i tried is

$array = str_split($aa, 1);
sort($array);
foreach ($array as $val) {
echo $val."<br>";
}

But this orders only the string in $aa; example string = hellow output is ehllow. but i want order the output of $aa in the while loop

Just Use

$aa = 'hellow';
$array = str_split($aa, 1);

foreach ($array as $val) {
echo $val."<br>";
}

Result:

h e l l o w

No need to use explode() and than loop it. Just put that string in query and it will work.Change your query to use IN() for searching emails and do order by so that you will get the data in ascending order itself. you can try like this:

$eex = mysqli_query($database->connection,"SELECT * FROM contacts where email IN ($email) and owner = '$session->username' order by email") or die(mysqli_error());
    while($zzz = mysqli_fetch_array($eex)){


     if(empty($zzz['bedrijfsnaam'])){
        $aa = "<font size='2'>".ucfirst($zzz['name'])." ".ucfirst($zzz['lastname'])."</font>";
    }else{
     $aa = "<font size='2'>".ucfirst($zzz['bedrijfsnaam'])."</font>";
    }
    echo $aa;

     }