a::sort($array, $field, $direction = 'desc', $method = 0)
Sorts a multi-dimensional array by a certain column
-
$array (array)
The source array -
$field (string)
The name of the column -
$direction (string)
desc (descending) or asc (ascending) -
$method (\const)
A PHP sort method flag or 'natural' for natural sorting, which is not supported in PHP by sort flags -
return (array)
The sorted array
Example
$array[0] = array(
'id' => 1,
'username' => 'bastian',
);
$array[1] = array(
'id' => 2,
'username' => 'peter',
);
$array[3] = array(
'id' => 3,
'username' => 'john',
);
$sorted = a::sort($array, 'username ASC');
// Array
// (
// [0] => Array
// (
// [id] => 1
// [username] => bastian
// )
// [1] => Array
// (
// [id] => 3
// [username] => john
// )
// [2] => Array
// (
// [id] => 2
// [username] => peter
// )
// )