modifs.mineures sans commentaires
This commit is contained in:
parent
42b18bf663
commit
5afd3f6666
|
@ -161,10 +161,15 @@ class cl {
|
|||
* si $keys est vide ou null, retourner true
|
||||
*/
|
||||
static final function phas($array, $pkey): bool {
|
||||
if ($pkey !== null && !is_array($pkey)) {
|
||||
# optimisations
|
||||
if ($pkey === null || $pkey === []) {
|
||||
return true;
|
||||
} elseif (is_int($pkey) || (is_string($pkey) && strpos($pkey, ".") === false)) {
|
||||
return self::has($array, $pkey);
|
||||
} elseif (!is_array($pkey)) {
|
||||
$pkey = explode(".", strval($pkey));
|
||||
}
|
||||
if ($pkey === null || $pkey === []) return true;
|
||||
# phas
|
||||
$first = true;
|
||||
foreach($pkey as $key) {
|
||||
if ($key === "" && $first) {
|
||||
|
@ -200,10 +205,15 @@ class cl {
|
|||
* si $keys est vide ou null, retourner $default
|
||||
*/
|
||||
static final function pget($array, $pkey, $default=null) {
|
||||
if ($pkey !== null && !is_array($pkey)) {
|
||||
# optimisations
|
||||
if ($pkey === null || $pkey === []) return $default;
|
||||
elseif ($pkey === "") return $array;
|
||||
elseif (is_int($pkey) || (is_string($pkey) && strpos($pkey, ".") === false)) {
|
||||
return self::get($array, $pkey, $default);
|
||||
} elseif (!is_array($pkey)) {
|
||||
$pkey = explode(".", strval($pkey));
|
||||
}
|
||||
if ($pkey === null || $pkey === []) return true;
|
||||
# pget
|
||||
$value = $array;
|
||||
$first = true;
|
||||
foreach($pkey as $key) {
|
||||
|
@ -238,20 +248,27 @@ class cl {
|
|||
* modifier la valeur au chemin de clé $keys dans le tableau $array
|
||||
*
|
||||
* utiliser la clé "" (chaine vide) en dernière position pour rajouter à la fin, e.g
|
||||
* - _pset($array, [""], $value) est équivalent à $array[] = $value
|
||||
* - _pset($array, ["a", "b", ""], $value) est équivalent à $array["a"]["b"][] = $value
|
||||
* - pset($array, [""], $value) est équivalent à $array[] = $value
|
||||
* - pset($array, ["a", "b", ""], $value) est équivalent à $array["a"]["b"][] = $value
|
||||
* la clé "" n'a pas de propriété particulière quand elle n'est pas en dernière position
|
||||
*
|
||||
* si $keys est vide ou null, $array est remplacé par $value
|
||||
*/
|
||||
static final function pset(&$array, $pkey, $value): void {
|
||||
if ($pkey !== null && !is_array($pkey)) {
|
||||
$pkey = explode(".", strval($pkey));
|
||||
}
|
||||
# optimisations
|
||||
if ($pkey === null || $pkey === []) {
|
||||
$array = $value;
|
||||
return;
|
||||
} elseif ($pkey === "") {
|
||||
$array[] = $value;
|
||||
return;
|
||||
} elseif (is_int($pkey) || (is_string($pkey) && strpos($pkey, ".") === false)) {
|
||||
self::set($array, $pkey, $value);
|
||||
return;
|
||||
} elseif (!is_array($pkey)) {
|
||||
$pkey = explode(".", strval($pkey));
|
||||
}
|
||||
# pset
|
||||
self::ensure_array($array);
|
||||
$current =& $array;
|
||||
$key = null;
|
||||
|
@ -285,12 +302,6 @@ class cl {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* supprimer la valeur au chemin $keys fourni sous forme de tableau
|
||||
*/
|
||||
static final function pdel_a(&$array, ?array $pkey): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* supprimer la valeur au chemin de clé $keys dans $array
|
||||
*
|
||||
|
@ -298,14 +309,19 @@ class cl {
|
|||
* si $keys est vide ou null, $array devient null
|
||||
*/
|
||||
static final function pdel(&$array, $pkey): void {
|
||||
if ($array === false || $array === null) return;
|
||||
if ($pkey !== null && !is_array($pkey)) {
|
||||
$pkey = explode(".", strval($pkey));
|
||||
}
|
||||
if ($pkey === null || $pkey === []) {
|
||||
# optimisations
|
||||
if ($array === null || $array === false) {
|
||||
return;
|
||||
} elseif ($pkey === null || $pkey === []) {
|
||||
$array = null;
|
||||
return;
|
||||
} elseif (is_int($pkey) || (is_string($pkey) && strpos($pkey, ".") === false)) {
|
||||
self::del($array, $pkey);
|
||||
return;
|
||||
} elseif (!is_array($pkey)) {
|
||||
$pkey = explode(".", strval($pkey));
|
||||
}
|
||||
# pdel
|
||||
self::ensure_array($array);
|
||||
$current =& $array;
|
||||
$key = null;
|
||||
|
|
Loading…
Reference in New Issue