sort en place
This commit is contained in:
parent
14ce2e3107
commit
e71936c10a
19
src/A.php
19
src/A.php
|
@ -213,4 +213,23 @@ class A {
|
||||||
static final function filter_not_equals($dest, $value): void { self::filter_if($dest, cv::not_equals($value)); }
|
static final function filter_not_equals($dest, $value): void { self::filter_if($dest, cv::not_equals($value)); }
|
||||||
static final function filter_same($dest, $value): void { self::filter_if($dest, cv::same($value)); }
|
static final function filter_same($dest, $value): void { self::filter_if($dest, cv::same($value)); }
|
||||||
static final function filter_not_same($dest, $value): void { self::filter_if($dest, cv::not_same($value)); }
|
static final function filter_not_same($dest, $value): void { self::filter_if($dest, cv::not_same($value)); }
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
static final function sort(?array &$array, int $flags=SORT_REGULAR, bool $assoc=false): void {
|
||||||
|
if ($array === null) return;
|
||||||
|
if ($assoc) asort($array, $flags);
|
||||||
|
else sort($array, $flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
static final function ksort(?array &$array, int $flags=SORT_REGULAR): void {
|
||||||
|
if ($array === null) return;
|
||||||
|
ksort($array, $flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
static final function usort(?array &$array, array $keys, bool $assoc=false): void {
|
||||||
|
if ($array === null) return;
|
||||||
|
if ($assoc) uasort($array, cl::compare($keys));
|
||||||
|
else usort($array, cl::compare($keys));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
11
src/cl.php
11
src/cl.php
|
@ -724,15 +724,12 @@ class cl {
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
static final function sorted(?array $array, int $flags=SORT_REGULAR, bool $assoc=false): ?array {
|
static final function sorted(?array $array, int $flags=SORT_REGULAR, bool $assoc=false): ?array {
|
||||||
if ($array === null) return null;
|
A::sort($array, $flags, $assoc);
|
||||||
if ($assoc) asort($array, $flags);
|
|
||||||
else sort($array, $flags);
|
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
static final function ksorted(?array $array, int $flags=SORT_REGULAR): ?array {
|
static final function ksorted(?array $array, int $flags=SORT_REGULAR): ?array {
|
||||||
if ($array === null) return null;
|
A::ksort($array, $flags);
|
||||||
ksort($array, $flags);
|
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -763,9 +760,7 @@ class cl {
|
||||||
}
|
}
|
||||||
|
|
||||||
static final function usorted(?array $array, array $keys, bool $assoc=false): ?array {
|
static final function usorted(?array $array, array $keys, bool $assoc=false): ?array {
|
||||||
if ($array === null) return null;
|
A::usort($array, $keys, $assoc);
|
||||||
if ($assoc) uasort($array, self::compare($keys));
|
|
||||||
else usort($array, self::compare($keys));
|
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue