{"id":28300294,"url":"https://github.com/mauretto78/array-query","last_synced_at":"2025-09-13T07:20:26.880Z","repository":{"id":62525395,"uuid":"100462926","full_name":"mauretto78/array-query","owner":"mauretto78","description":"Array Query is a library that allows you to perform queries on multidimensional arrays.","archived":false,"fork":false,"pushed_at":"2019-10-22T14:50:49.000Z","size":72,"stargazers_count":12,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-24T11:56:05.884Z","etag":null,"topics":["array-filter","array-helper","array-iteration","array-manipulations","php","php-library"],"latest_commit_sha":null,"homepage":null,"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/mauretto78.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":"2017-08-16T07:49:56.000Z","updated_at":"2024-12-13T12:24:17.000Z","dependencies_parsed_at":"2022-11-02T15:31:02.817Z","dependency_job_id":null,"html_url":"https://github.com/mauretto78/array-query","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/mauretto78/array-query","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauretto78%2Farray-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauretto78%2Farray-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauretto78%2Farray-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauretto78%2Farray-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mauretto78","download_url":"https://codeload.github.com/mauretto78/array-query/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauretto78%2Farray-query/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274932980,"owners_count":25376291,"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-09-13T02:00:10.085Z","response_time":70,"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":["array-filter","array-helper","array-iteration","array-manipulations","php","php-library"],"created_at":"2025-05-23T15:20:40.932Z","updated_at":"2025-09-13T07:20:26.871Z","avatar_url":"https://github.com/mauretto78.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Array Query\n\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mauretto78/array-query/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mauretto78/array-query/?branch=master)\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/b2f343d6-2459-4b6f-b2c9-c33a05a482d1/mini.png)](https://insight.sensiolabs.com/projects/b2f343d6-2459-4b6f-b2c9-c33a05a482d1)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/a17231a0420548e182ec58516cd1b562)](https://www.codacy.com/app/mauretto78/array-query?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=mauretto78/array-query\u0026amp;utm_campaign=Badge_Grade)\n[![Coverage Status](https://coveralls.io/repos/github/mauretto78/array-query/badge.svg?branch=master)](https://coveralls.io/github/mauretto78/array-query?branch=master)\n[![license](https://img.shields.io/github/license/mauretto78/array-query.svg)]()\n[![Packagist](https://img.shields.io/packagist/v/mauretto78/array-query.svg)]()\n\n**Array Query** allows you to perform queries on multidimensional arrays.\n\n## Use Cases\n\nThis library is suitable for you if you need to perform some queries on:\n\n* static php arrays\n* in-memory stored arrays\n* parsed json (or yaml) files\n\n## Basic Usage\n\nTo instantiate the QueryBuilder do the following:\n\n```php\nuse ArrayQuery\\QueryBuilder;\n\n$array = [\n    [\n        'id' =\u003e 1,\n        'title' =\u003e 'Leanne Graham',\n        'email' =\u003e 'Sincere@april.biz',\n        'rate' =\u003e 5,\n        'company' =\u003e [\n            'name' =\u003e 'Romaguera-Jacobson',\n            'catchPhrase' =\u003e 'Face to face bifurcated interface',\n            'bs' =\u003e 'e-enable strategic applications'\n        ]\n    ],\n    [\n        'id' =\u003e 2,\n        'title' =\u003e 'Ervin Howell',\n        'email' =\u003e 'Shanna@melissa.tv',\n        'rate' =\u003e 3,\n        'company' =\u003e [\n            'name' =\u003e 'Robel-Corkery',\n            'catchPhrase' =\u003e 'Multi-tiered zero tolerance productivity',\n            'bs' =\u003e 'transition cutting-edge web services'\n        ]\n    ],\n    [\n        'id' =\u003e 3,\n        'title' =\u003e 'Clementine Bauch',\n        'email' =\u003e 'Nathan@yesenia.net',\n        'rate' =\u003e 4,\n        'company' =\u003e [\n            'name' =\u003e 'Keebler LLC',\n            'catchPhrase' =\u003e 'User-centric fault-tolerant solution',\n            'bs' =\u003e 'revolutionize end-to-end systems'\n        ]\n    ],\n    // ..\n]\n\nQueryBuilder::create($array);\n\n// to add an element to your array. Do this BEFORE make a query on the array\n$element = [\n   'id' =\u003e 4,\n   'title' =\u003e 'Patricia Lebsack',\n   'email' =\u003e 'Julianne.OConner@kory.org',\n   'rate' =\u003e 2,\n   'company' =\u003e [\n       'name' =\u003e 'Robel-Corkery',\n       'catchPhrase' =\u003e 'Multi-tiered zero tolerance productivity',\n       'bs' =\u003e 'transition cutting-edge web services'\n   ]\n];\n$qb-\u003eaddElement($element, 4);\n\n// to remove an element from array by his key. Do this BEFORE make a query on the array\n$qb-\u003eremoveElement(3);\n\n```\n\n## Data consistency\n\nQueryBuilder checks for your data consistency. If an inconsistency is detected a `NotConsistentDataException` will be raised:\n\n```php\nuse ArrayQuery\\QueryBuilder;\n\n$array = [\n    [\n        'id' =\u003e 1,\n        'title' =\u003e 'Leanne Graham',\n        'email' =\u003e 'Sincere@april.biz',\n        'rate' =\u003e 5,\n        'company' =\u003e [\n            'name' =\u003e 'Romaguera-Jacobson',\n            'catchPhrase' =\u003e 'Face to face bifurcated interface',\n            'bs' =\u003e 'e-enable strategic applications'\n        ]\n    ],\n    [\n        'id' =\u003e 2,\n        'title' =\u003e 'Ervin Howell',\n        'email' =\u003e 'Shanna@melissa.tv',\n        'rate' =\u003e 3,\n        'company' =\u003e [\n            'name' =\u003e 'Robel-Corkery',\n            'catchPhrase' =\u003e 'Multi-tiered zero tolerance productivity',\n            'bs' =\u003e 'transition cutting-edge web services'\n        ]\n    ],\n    [\n        'id' =\u003e 3,\n        'title' =\u003e 'Clementine Bauch',\n        'email' =\u003e 'Nathan@yesenia.net',\n        'rate' =\u003e 4,\n        'company' =\u003e [\n            'name' =\u003e 'Keebler LLC',\n            'catchPhrase' =\u003e 'User-centric fault-tolerant solution',\n            'bs' =\u003e 'revolutionize end-to-end systems'\n        ],\n        'extra-field' =\u003e 'this is an extra field'\n    ],\n]\n\n// NotConsistentDataException will be raised\nQueryBuilder::create($array);\n\n```\n\n## Quering, sorting and get results\n\nYou can perform queries on your array. You can concatenate criteria:\n\n```php\nuse ArrayQuery\\QueryBuilder;\n\n// ..\n\n$qb = QueryBuilder::create($array);\n$qb\n    -\u003eaddCriterion('title', 'Leanne', 'CONTAINS')\n    -\u003eaddCriterion('rate', '3', '\u003e')\n    -\u003esortedBy('title', 'DESC');\n\n// you can search by nested keys    \n$qb-\u003eaddCriterion('company.name', 'Romaguera-Jacobson');\n\n// get results    \nforeach ($qb-\u003egetResults() as $element){\n    // ...\n}\n\n// get first result\n$first = $qb-\u003egetFirstResult();\n\n// get last result\n$last = $qb-\u003egetLastResult();\n\n// get a result by index\n$thirdResult = $qb-\u003egetResult(3);\n```\n\n### Avaliable criteria operators\n\n* `=` (default operator, can be omitted)\n* `\u003e`\n* `\u003c`\n* `\u003c=`\n* `\u003e=`\n* `!=`\n* `ARRAY_MATCH`\n* `CONTAINS` (case insensitive)\n* `ENDS_WITH`\n* `EQUALS_DATE`\n* `GT_DATE`\n* `GTE_DATE`\n* `IN_ARRAY`\n* `IN_ARRAY_INVERSED`\n* `LT_DATE`\n* `LTE_DATE`\n* `STARTS_WITH`\n\n### Avaliable sorting operators\n\n* `ASC` (default operator, can be omitted)\n* `DESC`\n* `DATE_ASC`\n* `DATE_DESC`\n\n## Joins\n\nYou can join arrays. Please consider this full example:\n\n```php\nuse ArrayQuery\\QueryBuilder;\n\n$users = [\n    [\n        'id' =\u003e 1,\n        'name' =\u003e 'Mauro Cassani',\n        'id_category' =\u003e 3,\n        'email' =\u003e 'assistenza@easy-grafica.com'\n    ],[\n        'id' =\u003e 2,\n        'name' =\u003e 'Mario Rossi',\n        'id_category' =\u003e 3,\n        'email' =\u003e 'mario.rossi@gmail.com'\n    ],[\n        'id' =\u003e 3,\n        'name' =\u003e 'Maria Bianchi',\n        'id_category' =\u003e 1,\n        'email' =\u003e 'maria.bianchi@gmail.com'\n    ]\n];\n$category = [\n    'id' =\u003e 3,\n    'name' =\u003e 'Web Developer'\n];\n\n$qb = QueryBuilder::create($users)\n    -\u003ejoin($category, 'category', 'id_category', 'id')\n    -\u003eaddCriterion('category.id', 3);\n\nforeach ($qb-\u003egetResults() as $element){\n    // ...\n}\n```\n\n## Limit and Offset \n\nYou can add criteria and specify limit and offset for your query results:\n\n```php\nuse ArrayQuery\\QueryBuilder;\n\n$qb = QueryBuilder::create($array);\n$qb\n    -\u003eaddCriterion('title', ['Leanne'], 'IN_ARRAY')\n    -\u003eaddCriterion('rate', '3', '\u003e')\n    -\u003esortedBy('title')\n    -\u003elimit(0, 10);\n\nforeach ($qb-\u003egetResults() as $element){\n    // ...\n}\n```\n\n## Working with dates\n\nYou can perform queries based on datetime fields. You can use `DATE_ASC` or `DATE_DESC` operator to sort results by date. You must specify **date format** if your format is not `YYYY-mm-dd`:\n\n```php\nuse ArrayQuery\\QueryBuilder;\n\n$qb = QueryBuilder::create($array);\n$qb\n    -\u003eaddCriterion('registration_date', '01/05/2017', 'GT_DATE', 'd/m/Y')\n    -\u003eaddCriterion('rate', '3', '\u003e')\n    -\u003esortedBy('registration_date', 'DATE_DESC', 'd/m/Y')\n    -\u003elimit(0, 10);\n\nforeach ($qb-\u003egetResults() as $element){\n    // ...\n}\n```\n\n## Aliases\n\nYou can use aliases by using the `as` keyword as a delimiter. Do the following:\n\n```php\nuse ArrayQuery\\QueryBuilder;\n\n$qb = QueryBuilder::create($array);\n$qb\n    -\u003eaddCriterion('name as n', 'Ervin Howell')\n    -\u003eaddCriterion('username as user', 'Antonette')\n    -\u003eaddCriterion('address.street as street', 'Victor Plains');\n\nforeach ($qb-\u003egetResults() as $element){\n    // ...\n    // now you have\n    // $element['n']\n    // $element['user']\n    // $element['street']\n}\n```\n\n## Shuffled results\n\nYou can shuffle query results by using `getShuffledResults` method:\n\n```php\nuse ArrayQuery\\QueryBuilder;\n\n$qb = QueryBuilder::create($array);\n\nforeach ($qb-\u003egetShuffledResults() as $element){\n    // ...\n}\n```\n\n## More examples\n\nPlease refer to [QueryBuilderTest](https://github.com/mauretto78/array-query/blob/master/tests/QueryBuilderTest.php) for more examples.\n\n## Support\n\nIf you found an issue or had an idea please refer [to this section](https://github.com/mauretto78/array-query/issues).\n\n## Authors\n\n* **Mauro Cassani** - [github](https://github.com/mauretto78)\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmauretto78%2Farray-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmauretto78%2Farray-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmauretto78%2Farray-query/lists"}