note 47292 deleted from function.array-multisort by cmb
| From: | cmb@php.net | Date: | Sun, 24 Nov 2019 09:07:19 +0000 |
| Subject: | note 47292 deleted from function.array-multisort by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213233@lists.php.net to get a copy of this message | ||
Note Submitter: Toni
----
An example to sort an array by 3 criteria:
$recordset is an array of results from a query to a database, that I sort using $matrix as auxiliary
array. First numeric, Second and Third alphabetically.
<?php
for($idx=0;$idx<$toShow;$idx++){
$matrix[0][$id]=$recordset[$id][0];
$matrix[1][$id]=$recordset[$id][1];
$matrix[2][$id]=$recordset[$id][10];
}
array_multisort($matrix[0], SORT_DESC, SORT_NUMERIC,$matrix[1], SORT_STRING, SORT_ASC,$matrix[2],
SORT_STRING, SORT_ASC);
?>