/ Published in: PHP
Orders a multi-dimensional array by one of it's fields.
There is also the option to treat this like an SQL-style 'order by' query with the $field value passed in (ie. 'user_id desc') to do reverse ordering.
There is also the option to treat this like an SQL-style 'order by' query with the $field value passed in (ie. 'user_id desc') to do reverse ordering.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
if ($field != '') { $reverse = true; } else { $reverse = false; } foreach ($array as $key => $a) { $ar[$key] = $a[$field]; } $counter=0; foreach ($ar as $k => $a) { $key = $keep_assoc ? $k : $counter; $array_redux[$key] = $array[$k]; $counter++; } $array = $array_redux; } return $array; }