|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-05-17 16:57 UTC] 8umucsxy at terra dot es
Description:
------------
There is a problem with array_multisort in languages other than English.
For special chars, as A with accent (?), the sorting does not correspond to what might expect from a MySQL SELECT with ORDER BY.
For example the code attached to the message
will sort the array in this way: ABADIA, ALVAREZ, BU?UEL, ZUBIETA, ?LVARES
while a MySQL SELECT with ORDER BY nombre ASC will yield
ABADIA, ?LVARES, ALVEREZ, BU?UEL, ZUBIETA
as A and ? are considered two different representations of the same letter.
Reproduce code:
---------------
foreach ($students as $key => $row){
$surname[$key] = $row['surname'];
}
array_multisort($surname, SORT_ASC, $students);
Expected result:
----------------
ABADIA, ?LVARES, ALVEREZ, BU?UEL, ZUBIETA
Actual result:
--------------
ABADIA, ALVAREZ, BU?UEL, ZUBIETA, ?LVARES
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 14:00:01 2025 UTC |
How can you have a feature request with reproducable code? And this is all already very possible: <?php setlocale(LC_ALL, 'es_ES'); $words = array( ABADIA, ALVAREZ, BU?UEL, ZUBIETA, ?LVARES ); sort( $words, SORT_LOCALE_STRING); var_dump($words); ?> outputs: array(5) { [0]=> string(6) "ABADIA" [1]=> string(7) "?LVARES" [2]=> string(7) "ALVAREZ" [3]=> string(6) "BU?UEL" [4]=> string(7) "ZUBIETA" }<?php require_once("includes/conn.php"); $sql = "SELECT * FROM apellidos.apellidos ORDER BY apellido"; $res = mysql_query($sql); while($row=mysql_fetch_object($res)){ echo $row->apellido . ","; } // while echo "<br>"; $students = array("BU?UEL", "ABADIA", "?LVARES", "ZUBIETA", "ALVAREZ"); foreach ($students as $key => $row){ $surname[$key] = $row['surname']; } array_multisort($surname, SORT_ASC, $students); for($i=0;$i<count($students);$i++){ echo $students[$i] . ", "; } // for ?>