How can I make "foreach" list items in alphabetical order
<p>I am looking to list items (or in this case game titles) in alphabetical order.</p>

<p>using php I am getting games from a mysql databse, i use foreach to easly list all games, but i need it to list them in alphabetical order.</p>

<p><strong>games.php</strong></p>

<pre><code>&lt;table style="width:100%;" class="hover"&gt;
    &lt;th style="width:5%;"&gt;A-Z&lt;/th&gt;
    &lt;th style="width:70%;"&gt;Games&lt;/th&gt;
    &lt;th style="width:10%;"&gt;Clans&lt;/th&gt;
    &lt;th style="width:10%;"&gt;Recruiting&lt;/th&gt;


    &lt;tr&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;None Specified&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;?php 
    $query = " 
        SELECT 
            az,
            games,
            clans,
            recruiting
        FROM games 
    "; 

    try 
    { 
        // These two statements run the query against your database table.
        $stmt = $db-&gt;prepare($query); 
        $stmt-&gt;execute(); 
    } 
    catch(PDOException $ex) 
    { 
        // Note: On a production website, you should not output $ex-&gt;getMessage(). 
        // It may provide an attacker with helpful information about your code.  
        die("Failed to run query: " . $ex-&gt;getMessage()); 
    } 

    // Finally, we can retrieve all of the found rows into an array using fetchAll 
    $rows = $stmt-&gt;fetchAll(); 
?&gt; 


&lt;?php foreach($rows as $row): ?&gt; 
    &lt;tr&gt;
        &lt;td&gt;&lt;?php echo $row['az']; ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;a href="/games/"&gt;&lt;?php echo $row['games']; ?&gt;&lt;/a&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $row['clans']; ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $row['recruiting']; ?&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;?php endforeach; ?&gt;


&lt;tr&gt;
    &lt;th style="width:5%;"&gt;A-Z&lt;/th&gt;
    &lt;th style="width:70%;"&gt;Games&lt;/th&gt;
    &lt;th style="width:10%;"&gt;Clans&lt;/th&gt;
    &lt;th style="width:10%;"&gt;Recruiting&lt;/th&gt;  
&lt;/tr&gt;
&lt;/table&gt;
</code></pre>