ID: 37480
User updated by: 8umucsxy at terra dot es
Reported By: 8umucsxy at terra dot es
Status: Bogus
Bug Type: Feature/Change Request
PHP Version: 4.4.2
New Comment:
<?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
?>
Previous Comments:
------------------------------------------------------------------------
[2006-05-17 21:39:04] 8umucsxy at terra dot es
I include the code at the end of my comment.
Yes, that sorting you provide is possible and indeed more convenient,
but notice that this is just an example. I used array_multisort for a
real-life example where I needed to order by different keys, one
numeric, the other two strings, and I found the problem. Indeed the
only shortcut I was able to get was to temporaly disable the accent
character by including another key with the letter converted to the
un-accented equivalen, i.e. "Á" => "A".
I believe the reason is that array_multisort uses A-Z,...Á..., etc., to
order, so including the charset as a parameter in a next version could
be interesting.
------------------------------------------------------------------------
[2006-05-17 21:30:30] [EMAIL PROTECTED]
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"
}
------------------------------------------------------------------------
[2006-05-17 16:57:21] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=37480&edit=1