title: Custom collation with php using usort
body: <p>I'm trying to sort an array by a custom alphabet (international names, none of the Collator locales put them in exactly the order that I want).</p>
  
  <p>I've stolen some code from <a href="https://stackoverflow.com/questions/6350510/how-can-i-sort-arrays-in-php-by-a-custom-alphabet">here</a> and have.</p>
  
  <pre><code> function compare_by_alphabet($str1, $str2){
       $alphabet = "AaÀàÁáÂâÅåÃãÄäÆæBbCcÇçDdÐðEeÈèÉéÊêËëFfGgHhIiÌìÍíÎîÏïJjKkLlMmNnÑñOoÒòÓóÔôÕõÖöØøPpQqRrSsßŠšTtUuÙùÚúÛûÜüVvWwXxYyŸÿÝýZzŽžÞþ0123456789";
       $l1 = strlen($str1);
       $l2 = strlen($str2);
       $c = min($l1, $l2);
  
       for ($i = 0; $i &lt; $c; $i++)
       {
           $s1 = substr($str1, $i, 1);
           $s2 = substr($str2, $i, 1);
           if ($s1===$s2) continue;
           $i1 = strpos($alphabet, $s1);
           if ($i1===false) continue;
           $i2 = strpos($alphabet, $s2);
           if ($i2===false) continue;
           if ($i2===$i1) continue;
           if ($i1 &lt; $i2) return -1;
           else return 1;
       }
       if ($l1 &lt; $l2) return -1;
       elseif ($l1 &gt; $l2) return 1;
       return 0;
   }
  </code></pre>
  
  <p>When I try</p>
  
  <pre><code>$names=["Schön","Åsberg","Zierer","Ås","Žižek","Schon","Asber"];
  usort($names, 'compare_by_alphabet');
  </code></pre>
  
  <p>I get <code>["Asber","Ås","Åsberg","Schön","Schon","Žižek","Zierer"]</code> - the two Schon's are the wrong was around, as are Žižek and Zierer.</p>
  
  <p>I'm missing something here. Can someone explain why this isn't behaving as expected, please? Or how I can fix it?</p>