RE: [PHP] Sorting array based on key string
| From: | Martin Towell | Date: | Fri, 19 Jul 2002 06:09:31 +0000 |
| Subject: | RE: [PHP] Sorting array based on key string | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-108445@lists.php.net to get a copy of this message | ||
dunno if this'll work... but here goes...
sort($data);
ksort($data);
but ksort() might mangle the order from sort(). In that case, you'll need to
write your sort routine that retains the old order
-----Original Message-----
From: Peter J. Pieczora [mailto:pjpieczora@sympatico.ca]
Sent: Friday, July 19, 2002 5:35 AM
To: php-general@lists.php.net
Subject: [PHP] Sorting array based on key string
Pardon my sloppy explanation but here it is:
how can i sort an array based on key element ie.
key values are: a1, a2 ,a3 ..., b1, b2 ,b3, ...c1, c1, c3...
so doing this:
while (list($k, $v) = each($data)) {
for ($i=0; $i<count($k); $i++) {
echo "$k[0] = $v\n<br>";
}
will list all the $k $v .
a = foo
a = bar
b = another foo
.......
and so on
Now, how can i sort it according to $k[0]
where $k[0] = a, than the same for all b's and so on.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php