array_sort_col()
Sort a list of rows (associative arrays) by one of their columns.
Syntax
array_sort_col(data, column, ascending)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
data |
array | yes | A list of associative arrays (rows). |
column |
string | yes | The key to sort by. |
ascending |
bool | yes | true for ascending, false for descending. |
Returns
A new array with the rows in sorted order.
Example
$items = fromjson($resp["body"]);
$sorted = array_sort_col($items, "qty", false); // highest qty first
sys_log("Top SKU: " . $sorted[0]["sku"]);
Example output
[
["sku" => "B2", "qty" => 7],
["sku" => "A1", "qty" => 3]
]
Notes
- Sorts in-memory arrays. To sort your own table data, use the
orderoption of records_query().
See also: array_search_col()