title: PHP sort list of subdomains by domain
body: <p>I have a list of domains (array)</p>
  
  <pre><code>sub1.dom1.tld1
  sub2.dom2.tld2
  sub1.sub2.dom1.tld1
  sub3.dom1.tld3
  </code></pre>
  
  <p>I want to achieve the following:</p>
  
  <pre><code>dom1.tld1
  -&gt; sub1.dom1.tld1
  -&gt; sub2.dom1.tld1
  --&gt; sub1.sub2.dom1.tld1
  
  dom2.tld2
  -&gt; sub2.dom2.tld2
  
  dom1.tld3
  -&gt; sub3.dom1.tld3
  </code></pre>
  
  <p>I have tried to adapt this, but it doesn't really fit:</p>
  
  <p><a href="https://stackoverflow.com/questions/21346422/how-to-alphabetically-sort-a-php-array-after-a-certain-character-in-a-string">How to alphabetically sort a php array after a certain character in a string</a></p>
  
  <p>I would appreciate any kind of help.</p>