phpsortinglocalenatsort

PHP natsort() with accented letters


I'm trying to sort an array like this

['České Budějovice',
 'Cidlina',
 'Praha 1',
 'Praha 10',
 'Praha 4']

in a natural way. The result should be

['Cidlina',
 'České Budějovice',
 'Praha 1',
 'Praha 4',
 'Praha 10']

The natsort() function itself does a great job sorting in a natural way (i.e. putting 'Praha 10' after 'Praha 4') but it puts the words that start with accented letters at the end.

Is there a way how to sort naturally while respecting the locale?


Solution

  • You can't with natsort.

    In project page you will find this:

    Comparison of characters is purely numeric, without taking character set or locale into account. So it is only correct for ASCII.