0

I've got a list already ordered alphabetically but words with special char (i.e. Cárdena) are outputed at the end of the list... is there a way to order alphabetically even the words with special characters in PHP?

The code outputting the list is:

for($i = $infLimit; $i <= $supLimit; $i++){ 
                        $adherido = $lista_adheridos_filtrada[$i];                          
                        $numberOfAdheridos =    count($lista_adheridos_filtrada);
                        $nombreAdherido = $adherido->getNombreEntidad();
echo '<li><a target="_blank" title="'.$nombreAdherido.'" href="' . $protocol . '://'.$_SERVER["SERVER_NAME"].'/empresas/'.$adherido->getNombreFicha(). '.htm' . ((isset($_REQUEST["lang"]) && $_REQUEST["lang"] == "en") ? "?lang=en": "") . '">'.$nombreAdherido.'</a></li>';
}

P.S: I tried sort($adherido) but it's not working.

user1499369
  • 51
  • 1
  • 10

1 Answers1

0

You may be looking for the PHP Collator class:

PHP Collator class documentation

So for example to sort in Spanish, you might do this:

$collator = new Collator('es_ES');
$collator->asort($adherido);
JDA3
  • 356
  • 3
  • 7
  • I tried to use it but it's not working at all. it gives me a blank page... i can't even output the array. I don't know if it's a bug or something... I'm using PHP 5.4.37. My code is: `for($i = $infLimit; $i <= $supLimit; $i++){ $adherido = $lista_adheridos_filtrada[$i]; $nombreAdherido = $adherido->getNombreEntidad(); $initial = strtoupper($nombreAdherido[0]); $coll = collator_create( 'es_ES' ); $nombreAdherido = collator_asort( $coll, $nombreAdherido );` – user1499369 Mar 01 '15 at 22:29