How do I alphabetize a list of domains in this way?
<p>So if I wanted to organize a list of websites alphabetically, and there were all of this form: example1.com, test.com, stackoverflow.com, google.com, it would be easy.  However, I want to also organize subdomains.  Consider the following three domains:</p>

<pre><code>a.domain.com
domain.com
anotherdomain.com
</code></pre>

<p>If I handed them over to software to alphabetize, they would be alphabetized like this:</p>

<pre><code>a.domain.com
anotherdomain.com
domain.com
</code></pre>

<p>However, this is not how I want them alphabetized.  I want them to be alphabetized by domain, and then by subdomain as a "tiebreaker," in other words, like this:</p>

<pre><code>anotherdomain.com
domain.com
a.domain.com
</code></pre>

<p>Could someone tell me how to code PHP (or JavaScript) to do this?  (You can assume that each "website" is on a fresh line of code.)</p>
