Use anonymous function as suggested by PHP manual
This commit is contained in:
parent
e35e2f3e0f
commit
d7118b4398
1 changed files with 6 additions and 8 deletions
14
src/Sort.php
14
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue