title: PHP group/sort an array by 3 letter country code
body: <p>I have this array:</p>
  
  <pre><code>  [1]=&gt;
    array(4) {
      ["id"]=&gt;
      string(2) "31"
      ["slug"]=&gt;
      string(11) "montpellier"
      ["title"]=&gt;
      string(11) "Montpellier"
      ["country"]=&gt;
      string(3) "fra"
    }
    [2]=&gt;
    array(4) {
      ["id"]=&gt;
      string(2) "30"
      ["slug"]=&gt;
      string(4) "york"
      ["title"]=&gt;
      string(4) "York"
      ["country"]=&gt;
      string(3) "gbr"
    }
    [3]=&gt;
    array(4) {
      ["id"]=&gt;
      string(2) "29"
      ["slug"]=&gt;
      string(4) "hull"
      ["title"]=&gt;
      string(4) "Hull"
      ["country"]=&gt;
      string(3) "gbr"
  </code></pre>
  
  <p>and this other array:</p>
  
  <pre><code>$new_country = array(
      'gbr' =&gt; 'Great Britain',
      'fra' =&gt; 'France',
      'ita' =&gt; 'Italy',
      'de' =&gt; 'Germany',
      'esp' =&gt; 'Spain'    
  );
  </code></pre>
  
  <p>What exact function should i run on the array to run it through the $new_country array and produce the output below?</p>
  
  <p>I'd like to produce this output:</p>
  
  <pre><code>&lt;h2&gt;France&lt;/h2&gt;
  &lt;p&gt;Montpellier&lt;/h2&gt;
  
  &lt;h2&gt;Great Britain&lt;/h2&gt;
  &lt;p&gt;York&lt;/p&gt;
  &lt;p&gt;Hull&lt;/p&gt;
  </code></pre>
  
  <p>EDIT</p>
  
  <p>The best answer so far produces this output (countries are duplicated):</p>
  
  <pre><code>Great Britain
  Durham
  France
  Montpellier
  Great Britain
  York
  Hull
  Bradford
  Leeds
  Germany
  Berlin
  Great Britain
  Leicester
  Colchester
  Oxford
  Nottingham
  Newcastle
  St. Andrews
  Loughborough
  Chester
  Ipswich
  Bangor
  Wolverhampton
  Liverpool
  Italy
  Rome
  Great Britain
  Dundee
  Sheffield
  Bristol
  Birmingham
  Spain
  Madrid
  Barcelona
  France
  Paris
  Great Britain
  London
  Manchester
  Edinburgh
  Italy
  Turin
  Great Britain
  Glasgow
  </code></pre>