Implements partial support for XPath 2.0.
public static extract ( array $data, string $path = null, array $options = [] ) : array | ||
$data | array | An array of data to extract from. |
$path | string | An absolute XPath 2.0 path. Only absolute paths starting with a single slash are supported right now. Implemented selectors: - `'/User/id'`: Similar to the classic {n}.User.id. - `'/User[2]/name'`: Selects the name of the second User. - `'/User[id>2]'`: Selects all Users with an id > 2. - `'/User[id>2][<5]'`: Selects all Users with an id > 2 but < 5. - `'/Post/Comment[author_name=John]/../name'`: Selects the name of all posts that have at least one comment written by John. - `'/Posts[name]'`: Selects all Posts that have a `'name'` key. - `'/Comment/.[1]'`: Selects the contents of the first comment. - `'/Comment/.[:last]'`: Selects the last comment. - `'/Comment/.[:first]'`: Selects the first comment. - `'/Comment[text=/lithium/i]`': Selects the all comments that have a text matching the regex `/lithium/i`. - `'/Comment/@*'`: Selects all key names of all comments. |
$options | array | Currently only supports `'flatten'` which can be disabled for higher XPath-ness. |
return | array | An array of matched items. |