note 65191 deleted from function.array-multisort by bjori
| From: | bjori@php.net | Date: | Wed, 26 Apr 2006 15:37:32 +0000 |
| Subject: | note 65191 deleted from function.array-multisort by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109750@lists.php.net to get a copy of this message | ||
Note Submitter: p dot leblanc at caplaser dot fr
Reason: bad code
----
<?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');
*/
?>