diff --git a/src/Sort.php b/src/Sort.php index c2d221f..5473208 100644 --- a/src/Sort.php +++ b/src/Sort.php @@ -52,19 +52,17 @@ class Sort */ public static function by($field, &$array, $direction = Sort::ASC) { - usort($array, create_function('$a, $b', ' - $a = $a["' . $field . '"]; - $b = $b["' . $field . '"]; + usort($array, function ($a, $b) use ($field, $direction) { + $a = $a[$field]; + $b = $b[$field]; - if ($a == $b) - { + if ($a === $b) { return 0; } - return ($a ' . ($direction == Sort::DESC ? '>' : '<') .' $b) ? -1 : 1; - ')); + return ($a < $b ? -1 : 1) * ($direction === Sort::DESC ? -1 : 1); + }); return true; } } -