note 21792 modified in function.array-multisort by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:45:53 +0000 |
| Subject: | note 21792 modified in function.array-multisort by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79869@lists.php.net to get a copy of this message | ||
This example for sorting SQL results is very usefull, except the author mixed up the
array_multisort() arguments :
<?php
//Get table output into $rows array
$result = mysql_query("SELECT field1, field2 from table");
while ($rows[] = mysql_fetch_array($result)) {}
//Sort on field2
foreach ($rows as $val) {
$sortarray[] = $val['field2'];
}
array_multisort($sortarray,$rows);
?>
//Now, $rows is sorted on field2
--was--
This example for sorting SQL results is very usefull, except the author mixed up the
array_multisort() arguments :
//Get table output into $rows array
$result = mysql_query("SELECT field1, field2 from table");
while ($rows[] = mysql_fetch_array($result)) {}
//Sort on field2
foreach ($rows as $val) {
$sortarray[] = $val['field2'];
}
array_multisort($sortarray,$rows);
//Now, $rows is sorted on field2
http://php.net/manual/en/function.array-multisort.php