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
|
* si $keys est vide ou null, retourner true
|
||||||
*/
|
*/
|
||||||
static final function phas($array, $pkey): bool {
|
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));
|
$pkey = explode(".", strval($pkey));
|
||||||
}
|
}
|
||||||
if ($pkey === null || $pkey === []) return true;
|
# phas
|
||||||
$first = true;
|
$first = true;
|
||||||
foreach($pkey as $key) {
|
foreach($pkey as $key) {
|
||||||
if ($key === "" && $first) {
|
if ($key === "" && $first) {
|
||||||
|
@ -200,10 +205,15 @@ class cl {
|
||||||
* si $keys est vide ou null, retourner $default
|
* si $keys est vide ou null, retourner $default
|
||||||
*/
|
*/
|
||||||
static final function pget($array, $pkey, $default=null) {
|
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));
|
$pkey = explode(".", strval($pkey));
|
||||||
}
|
}
|
||||||
if ($pkey === null || $pkey === []) return true;
|
# pget
|
||||||
$value = $array;
|
$value = $array;
|
||||||
$first = true;
|
$first = true;
|
||||||
foreach($pkey as $key) {
|
foreach($pkey as $key) {
|
||||||
|
@ -238,20 +248,27 @@ class cl {
|
||||||
* modifier la valeur au chemin de clé $keys dans le tableau $array
|
* 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
|
* utiliser la clé "" (chaine vide) en dernière position pour rajouter à la fin, e.g
|
||||||
* - _pset($array, [""], $value) est équivalent à $array[] = $value
|
* - pset($array, [""], $value) est équivalent à $array[] = $value
|
||||||
* - _pset($array, ["a", "b", ""], $value) est équivalent à $array["a"]["b"][] = $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
|
* 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
|
* si $keys est vide ou null, $array est remplacé par $value
|
||||||
*/
|
*/
|
||||||
static final function pset(&$array, $pkey, $value): void {
|
static final function pset(&$array, $pkey, $value): void {
|
||||||
if ($pkey !== null && !is_array($pkey)) {
|
# optimisations
|
||||||
$pkey = explode(".", strval($pkey));
|
|
||||||
}
|
|
||||||
if ($pkey === null || $pkey === []) {
|
if ($pkey === null || $pkey === []) {
|
||||||
$array = $value;
|
$array = $value;
|
||||||
return;
|
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);
|
self::ensure_array($array);
|
||||||
$current =& $array;
|
$current =& $array;
|
||||||
$key = null;
|
$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
|
* 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
|
* si $keys est vide ou null, $array devient null
|
||||||
*/
|
*/
|
||||||
static final function pdel(&$array, $pkey): void {
|
static final function pdel(&$array, $pkey): void {
|
||||||
if ($array === false || $array === null) return;
|
# optimisations
|
||||||
if ($pkey !== null && !is_array($pkey)) {
|
if ($array === null || $array === false) {
|
||||||
$pkey = explode(".", strval($pkey));
|
return;
|
||||||
}
|
} elseif ($pkey === null || $pkey === []) {
|
||||||
if ($pkey === null || $pkey === []) {
|
|
||||||
$array = null;
|
$array = null;
|
||||||
return;
|
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);
|
self::ensure_array($array);
|
||||||
$current =& $array;
|
$current =& $array;
|
||||||
$key = null;
|
$key = null;
|
||||||
|
|
Loading…
Reference in New Issue