modifs.mineures sans commentaires
This commit is contained in:
parent
86a49f98e2
commit
1d0aba7215
24
src/cl.php
24
src/cl.php
|
@ -2,6 +2,7 @@
|
|||
namespace nur\sery;
|
||||
|
||||
use ArrayAccess;
|
||||
use nur\sery\php\func;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
|
@ -235,6 +236,29 @@ class cl {
|
|||
return self::select(cl::merge($array, $merge), $mappings);
|
||||
}
|
||||
|
||||
/**
|
||||
* construire un sous-ensemble du tableau $array en sélectionnant les clés de
|
||||
* $includes qui ne sont pas mentionnées dans $excludes.
|
||||
*
|
||||
* - si $includes===null && $excludes===null, retourner le tableau inchangé
|
||||
* - si $includes vaut null, prendre toutes les clés
|
||||
*
|
||||
*/
|
||||
static final function xselect($array, ?array $includes, ?array $excludes=null): ?array {
|
||||
if ($array === null) return null;
|
||||
$array = self::withn($array);
|
||||
if ($includes === null && $excludes === null) return $array;
|
||||
if ($includes === null) $includes = array_keys($array);
|
||||
if ($excludes === null) $excludes = [];
|
||||
$result = [];
|
||||
foreach ($array as $key => $value) {
|
||||
if (!in_array($key, $includes)) continue;
|
||||
if (in_array($key, $excludes)) continue;
|
||||
$result[$key] = $value;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* si $array est un array ou une instance de ArrayAccess, créer ou modifier
|
||||
* l'élément dont la clé est $key
|
||||
|
|
|
@ -25,4 +25,8 @@ class G {
|
|||
static final function set(string $name, ?string $value): void {
|
||||
$_GET[$name] = $value;
|
||||
}
|
||||
|
||||
static final function xselect(?array $includes, ?array $excludes=null): array {
|
||||
return cl::xselect($_GET, $includes, $excludes);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue