1

Okay my function order alphabetical all my values correctly, except, when I have in a field some name like (à,è,é,... etc ). there is a way i can order it too, i will show my code, thanks.

usort($xmls, "sortbyname" );

function sortbyname($a, $b){
    return strcmp($a[name],$b[name]);
}

print_r( $xmls );

As i said, it is fine , it works fine with this letters = a,b,c,d,e...etc, but when it read some letter like : 'É', it just put in the last position, because it read like a special character i guess, thanks you all.

Example INPUT - OUTPUT

$input = a,  é,d, e, ,f, g,b, c,á,h, i.... etc
$output = a,á,b,c,d,e,é,f,g,h,i .... ect

Thanks guys..

someone give me this as answer: Sort an array with special characters in PHP

but it doesnt work, because it give me this as input-output:

$input = a,  é,d, e, ,f, g,b, c,á,h, i.... etc
$output = á,é,a,,b,c,d,e,f,g,h,i .... ect

so obviusly thats wrong, thanks

Community
  • 1
  • 1
Alberto Acuña
  • 512
  • 3
  • 9
  • 28

1 Answers1

0

function($a, $b) {
            $trans = array("á" => "a", "é" => "e", "í" => "i", "ó" => "o", "ö" => "o" ,"ő" => "o" ,"ú" => "u", "ü" => "u", "ű" => "u");
            $at = mb_strtolower($a['name'],'UTF-8');
            $at = strtr($at, $trans);
            $bt = mb_strtolower($b['name'],'UTF-8');
            $bt = strtr($bt, $trans);
            return strcmp($at, $bt );
        }

This solved it for me as a Hungarian. Otherwise it didn't work for me either.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 20 '23 at 21:53