note 103138 rejected from collator.asort by danbrown
| From: | danbrown@php.net | Date: | Mon, 28 Mar 2011 17:30:25 +0000 |
| Subject: | note 103138 rejected from collator.asort by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-178272@lists.php.net to get a copy of this message | ||
Note Submitter: jeff_walter at kace dot com
----
The above example has a bug. Should be:
function natsortIntl($number) {
return sprintf('%032d', $number);
}
function sortIntl($array, $natural = true) {
$data = $array;
if ($natural === true) {
$data = preg_replace_callback('~([0-9]+)~', 'natsortIntl', $data);
}
collator_asort(collator_create('root'), $data);
return array_intersect_key($data, $array); <--- This is correct.
}