search()
Collect all values matching a wildcard path.
Signature
php
JsonFast::search(
string $json,
string $path,
?int $output = OUTPUT_ARRAY
): mixedParameters
| Name | Type | Default | Description |
|---|---|---|---|
$json | string | — | JSON document |
$path | string | — | Path with [*] wildcard segments |
$output | ?int | OUTPUT_ARRAY | Output mode |
Path syntax
Use [*] to match every element at that array level:
| Path | Meaning |
|---|---|
users[*].email | Every email under every users entry |
items[*].tags[*] | Nested wildcards (when structure allows) |
Wildcards are only supported in search(), not in get().
Returns
PHP array of matched values (default output). Empty array when nothing matches.
Examples
php
$json = <<<'JSON'
{
"users": [
{"email": "allan@example.com"},
{"email": "bob@example.com"}
]
}
JSON;
$emails = JsonFast::search($json, 'users[*].email');
// ['allan@example.com', 'bob@example.com']Filter pipeline:
php
$activeIds = JsonFast::search($feed, 'records[*].id');
// all ids across every record in the array