note 65191 added to function.array-multisort
| From: | p dot leblanc at caplaser dot fr | Date: | Wed, 26 Apr 2006 14:41:24 +0000 |
| Subject: | note 65191 added to function.array-multisort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-109747@lists.php.net to get a copy of this message | ||
<?php
/*
A simple way to use array_multisort() to sort a multidimensional array :
Here is how I managed to alphabetically sort an array of french words, with accents. I wanted
characters like 'é' or 'è' or 'ê' to be treated as simple
'e', otherwise these characters would appear after 'z' in alphabetical order.
*/
$words = array ('école', 'emploi', 'âtre', 'ennui',
'écrêmé', 'émoi', 'echo', 'alisé');// --- the
array ---
$search = array
('/é/','/è/','/ê/','/â/','/à /','/ô/');
$replace = array
('e','e','e','a','a','o');
for ($i=0; $i<count($words); $i++){
$words2[$i][0] = preg_replace($search, $replace, $words [$i]); // --- without accents ---
$words 2[$i][1] = $words [$i]; // --- with accents ---
}
array_multisort($words2);
for ($i=0; $i<count($words2); $i++){
$words[$i] = $words2[$i][1];
}
/* Now the array would be as follows :
$words = array ('alisé', 'âtre', 'echo', 'école',
'écrêmé', 'émoi','emploi', ennui');
*/
?>
----
Server IP: 195.221.21.36
Probable Submitter: 213.190.70.88
----
X-Spam-Status: Yes, hits=7.4 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HEAD_ILLEGAL_CHARS autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.array-multisort.php
Edit -- http://master.php.net/note/edit/65191
Del: integrated -- http://master.php.net/note/delete/65191/integrated
Del: useless -- http://master.php.net/note/delete/65191/useless
Del: bad code -- http://master.php.net/note/delete/65191/bad+code
Del: spam -- http://master.php.net/note/delete/65191/spam
Del: non-english -- http://master.php.net/note/delete/65191/non-english
Del: in docs -- http://master.php.net/note/delete/65191/in+docs
Del: other reasons-- http://master.php.net/note/delete/65191
Reject -- http://master.php.net/note/reject/65191
Search -- http://master.php.net/manage/user-notes.php