-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Wildcards #43
Comments
No, unfortunately this library doesn't directly support searching with wildcards. But it shouldn't be too hard to implement something like that yourself :) For example, you could split that path by the I doubt this library would add native support for wildcards since virtually all operations are designed to operate on a single fixed path (not multiple paths at once). |
One operation that could support wildcard without changing the whole design is the This is really useful for the scope which I'm using the library: I've written a small extension to the /**
* {@inheritdoc}
*/
public function remove(string $key): void
{
$currentValue =& $this->data;
$keyPath = self::keyToPathArray($key);
$endKey = array_pop($keyPath);
foreach ($keyPath as $currentKey) {
if ($currentKey === '*') { /** @todo Add is_iterable($currentValue) in the condition? */
foreach (array_keys($currentValue) as $concreteKey) {
// Replace first occurrence of .*. with the concrete key
// https://stackoverflow.com/questions/1252693/using-str-replace-so-that-it-only-acts-on-the-first-match
$this->remove(implode(sprintf('.%s.', $concreteKey), explode('.*.', $key, 2)));
}
}
if (!isset($currentValue[$currentKey])) {
return;
}
$currentValue =& $currentValue[$currentKey];
}
unset($currentValue[$endKey]);
} In my scenario this is enough, but for your library you should adapt the code for:
|
Hi,
Is it possible to use wildcards?
Sth. like this: "array.value.*.array.value"
Thank you
The text was updated successfully, but these errors were encountered: