Skip to content

Commit 943af6f

Browse files
committed
IHF: array_order_by helper added.
1 parent 9024948 commit 943af6f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/array.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,25 @@ function array_except_value(array $array, $value)
1616
return $array;
1717
}
1818
}
19+
20+
if (!function_exists('array_order_by')) {
21+
function array_order_by(array $array, $field1 = null, $sort1 = null, $_ = null)
22+
{
23+
$args = func_get_args();
24+
25+
$data = array_shift($args);
26+
foreach ($args as $argKey => $argValue) {
27+
if (is_string($argValue)) {
28+
$column = [];
29+
foreach ($data as $key => $item) {
30+
$column[$key] = $item[$argValue];
31+
}
32+
$args[$argKey] = $column;
33+
}
34+
}
35+
$args[] = &$data;
36+
call_user_func_array('array_multisort', $args);
37+
38+
return array_pop($args);
39+
}
40+
}

0 commit comments

Comments
 (0)