{"id":17696831,"url":"https://github.com/datashaman/array-filter","last_synced_at":"2025-09-12T04:39:28.359Z","repository":{"id":18533992,"uuid":"21734644","full_name":"datashaman/array-filter","owner":"datashaman","description":"Match PHP arrays against filters.","archived":false,"fork":false,"pushed_at":"2019-05-24T04:50:04.000Z","size":20,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-04T16:24:32.629Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/datashaman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-11T11:57:44.000Z","updated_at":"2023-08-02T18:51:04.000Z","dependencies_parsed_at":"2022-09-02T03:30:53.140Z","dependency_job_id":null,"html_url":"https://github.com/datashaman/array-filter","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/datashaman/array-filter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datashaman%2Farray-filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datashaman%2Farray-filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datashaman%2Farray-filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datashaman%2Farray-filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/datashaman","download_url":"https://codeload.github.com/datashaman/array-filter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datashaman%2Farray-filter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267320257,"owners_count":24068527,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-24T14:45:28.501Z","updated_at":"2025-07-27T07:08:33.793Z","avatar_url":"https://github.com/datashaman.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Array Filter\n===\n\nA literal port of the excellent Javascript library [ mmckegg / json-filter ](https://github.com/mmckegg/json-filter) to PHP.\n\nCredit to [ Matt McKegg ](https://github.com/mmckegg) for creating an incredibly useful, well-tested piece of software.\n\nMatch PHP arrays against filters.\n\n[![Build Status](https://travis-ci.org/datashaman/array-filter.svg?branch=master)](https://travis-ci.org/datashaman/array-filter)\n\n## Installation\n\n```shell\n$ composer require datashaman/array-filter\n```\n\n## Filters\n\nFilters are just arrays that have the keys and values you want your final array to have. e.g. if you wanted to require that the field `type` was always `person` your filter would be `{type: 'person'}`. \n\nIf things aren't so black and white, the following conditionals are available:\n\n#### $present\n\nSpecify that the value must not be null or false (i.e. 'truthy'). \n\n```php\narray(\n  'name' =\u003e array( '$present' =\u003e true )\n)\n```\n\n#### $any\n\nSpecify that the value can be anything. Useful when matching all keys.\n\n```php\narray(\n  'description' =\u003e array( '$any' =\u003e true )\n)\n```\n\n#### $contains\n\nFor matching against an array. The array must contain all of the values specified.\n\n```php\narray(\n  'tags' =\u003e array( '$contains' =\u003e array( 'cat', 'animal' ) )\n)\n```\n\n#### $excludes\n\nFor matching against an array. The array cannot contain any of the values specified.\n\n```php\narray(\n  'permissions' =\u003e array( '$excludes' =\u003e array( 'admin', 'mod' ) )\n)\n```\n\n#### $only\n\nThe value can only be one of the ones specified.\n\n```php\narray(\n  'gender' =\u003e array( '$only' =\u003e array( 'male', 'female', 'unknown' ) )\n)\n```\n\n#### $not\n\nThe value can be anything except one of the ones specified.\n\n```php\narray(\n  'browser' =\u003e array( '$not' =\u003e array( 'IE', 'Firefox' ) )\n)\n```\n\n#### $matchAny\n\nAllows a filter to branch into multiple filters when at least one must match.\n\n```php\narray(\n  '$matchAny' =\u003e array(\n    array( 'type' =\u003e \"Post\",\n      'state' =\u003e array( '$only' =\u003e array( 'draft', 'published' ) )\n    ),\n    array( 'type' =\u003e \"Comment\",\n      'state' =\u003e array( '$only' =\u003e array( 'pending', 'approved', 'spam' ) )\n    )\n  )\n)\n```\n\n#### $query\n\nSpecify a query to get the value to match. Uses `options.queryHandler`.\n\n```php\narray(\n  'type' =\u003e 'item',\n  'user_id' =\u003e array( '$query' =\u003e 'user.id' )\n)\n```\n\n#### $optional\n\nA shortcut for specifying a lot of $any filters at the same time.\n\n```php\narray(\n  '$optional' =\u003e array( 'description', 'color', 'age' )\n)\n```\n\nIs equivalent to:\n\n```php\narray(\n  'description' =\u003e array( '$any' =\u003e true ),\n  'color' =\u003e array( '$any' =\u003e true ),\n  'age' =\u003e array( '$any' =\u003e true )\n)\n```\n\n## API\n\n```php\nuse DataShaman\\ArrayFilter;\n\n$filter = new ArrayFilter;\n$filter-\u003echeckFilter($source, $filter, $options);\n```\n\n### checkFilter(source, filter, options)\n\n#### options:\n\n- **match**: specify: 'filter', 'source', 'any', 'all'\n  - filter: every filter permission must be satisfied (i.e. required fields)\n  - source: every source key must be specified in filter\n  - any: the keys don't matter, but if there is a match, they must pass\n  - all: all keys must be exactly the same, otherwise fails - for finding changed items - no $conditionals work in this mode\n- **queryHandler**: Accepts a function(query, localContext) that returns resulting value\n- **context**: Array to pass to the query handler\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatashaman%2Farray-filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatashaman%2Farray-filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatashaman%2Farray-filter/lists"}