I have an array which keys are words in portuguese and I'm trying to sort the keys without consider accents.
I have the following, code but it doesn't work.
$array = array('ábaco' => 1,
'aéreo' => 2,
'abecedário' => 3,
'andar' => 4,
'absurdo' => 5);
$locale = ( defined('PHP_OS') &&
stristr(PHP_OS, 'win') &&
!stristr(PHP_OS, 'darwin')) ? 'Portuguese_Brazil.1252' : 'pt_BR.UTF-8';
setlocale(LC_COLLATE, $locale);
var_dump($locale);
ksort($array, SORT_LOCALE_STRING);
var_dump($array);
The result is the following:
string 'pt_BR.UTF-8' (length=11)
array (size=5)
'abecedário' => int 3
'absurdo' => int 5
'andar' => int 4
'aéreo' => int 2
'ábaco' => int 1
The word 'ábaco' should be the first, for example, but it's the last one because of its first letter "á".
I'm running this script on a Mac with PHP 5.4.
This problem seems to be different than the one described on this question: PHP ksort seems unaffected by setlocale