0

I am working on a php code as shown below:

<?php
$age=array("Bam"=>"35","Bân"=>"37","Bao"=>"43");
ksort($age);

foreach($age as $x=>$x_value)
   {
   echo "Key=" . $x . ", Value=" . $x_value;
   echo "<br>";
   }
?>

The above php code display the following o/p:

Key=Bam, Value=35
Key=Bao, Value=43
Key=Bân, Value=37

Problem Statement:

I am wondering what changes I should make in the php code above so that it display the following o/p:

Key=Bam, Value=35
Key=Bân, Value=37
Key=Bao, Value=43
flash
  • 1,455
  • 11
  • 61
  • 132

1 Answers1

0

I experimented with some of the locale-based methods suggested, but eventually the only way I was able to get it to work was to use one of the remove_accents functions from here and then sort the array according to the order of the unaccented keys.

$unaccented = array_map('remove_accents', array_keys($age));
array_multisort($unaccented, $age);

Doesn't mean it won't work with setlocale etc, just that I wasn't able to make it work, but this may be a viable alternative.

Don't Panic
  • 41,125
  • 10
  • 61
  • 80