I have the following array which has both English and Russian words in it:
[0] => Airline_1
[1] => Second Air
[2] => Авиатор
[3] => Аврора
I'm using the following function to sort it:
uasort($newCompanyList, function ($a, $b) {
$at = iconv('UTF-8', 'ASCII//TRANSLIT', $a);
$bt = iconv('UTF-8', 'ASCII//TRANSLIT', $b);
return strcmp($at, $bt);
});
The expected result is this:
[0] => Airline_1
[2] => Авиатор
[3] => Аврора
[1] => Second Air
The problem is that it does sort the list, but it sorts them seperatelly, I need russian 'A' to be next to english 'A' if that makes sense. How may I achieve that?
You may try making an aggregated array of characters like:
Then apply the sorting based on the numeric key of the array.
It's better to apply recursion here, that if the first character is the same - check the second character, third, etc.
NOTE, that for example character
З
which has the equivalent sounding ofZ
, is positioned as the 9nth character in Russian alfabet, whileZ
being the last one in English, so it's best not to do that from UX point of view.