note 29340 deleted from function.array-multisort by aidan
| From: | aidan@php.net | Date: | Sun, 03 Oct 2004 10:57:31 +0000 |
| Subject: | note 29340 deleted from function.array-multisort by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77804@lists.php.net to get a copy of this message | ||
Note Submitter: tfraser at jeffsys dot net
----
A general function for sorting a multi-dimensional array by a specific column and order (assuming
that all rows of the array have the same indexes (columns)):
<?php
function array_csort(&$results, $column=0, $order=SORT_ASC) {
$keys = array_keys($arr[0]);
foreach ($results as $row)
$sortarr[] = $row[$keys[$column]];
array_multisort(&$sortarr, $order, &$results, $order);
} // array_csort
?>
Note that the array parameters to multisort must be passed by reference! This eluded me for a long
time...