Sorting
orderByKeys
Definition
Arr::orderByKeys(array $array, mixed $keys, bool $appendUnmatched = true): arrayDescription
Order associative array according to supplied keys order
Examples
$array = [
'foo',
'a' => 'bar',
'b' => 'test',
1,
'c' => ['test' => 2]
];
Arr::orderByKeys($array, 'a.0.c.1.b') ->
[
'a' => 'bar',
0 => 'foo',
'c' => ['test' => 2],
1 => 1,
'b' => 'test',
]
Arr::orderByKeys($array, 'a.0.c') ->
[
'a' => 'bar',
0 => 'foo',
'c' => ['test' => 2],
'b' => 'test',
1 => 1,
]
Arr::orderByKeys($array, 'a.0.c', false) ->
[
'a' => 'bar',
0 => 'foo',
'c' => ['test' => 2],
]sortByKeys
Definition
Description
Sort array of arrays using value specified by key(s)
Examples
sortObjects
Definition
Description
Sort array of objects by comparing result of supplied method name
$object1->$method(...$args) <=> $object2->$method(...$args)
Examples
Last updated
Was this helpful?