note 27371 deleted from function.sort by derick
| From: | derick@php.net | Date: | Wed, 31 Aug 2005 10:39:47 +0000 |
| Subject: | note 27371 deleted from function.sort by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-94503@lists.php.net to get a copy of this message | ||
Note Submitter: mbevan at marginsoftware dot com
----
I've noticed that if you try to sort an assoc. array, it strips the names of the elements, as
can be seen by the following code and it's output:
<?php
$fruitcolors = array ("lemon"=>"yellow",
"orange"=>"orange",
"banana"=>"yellow",
"apple"=>"red");
sort ($fruitcolors);
reset ($fruitcolors);
print_r($fruitcolors);
}
?>
Output:
Array
(
[0] => orange
[1] => red
[2] => yellow
[3] => yellow
)
Which is useless if the name of each element is important (as it is in the above example). How to
sort the above array without loosing the keys? There has to be a simple way of doing this that is
elusive to me.