{"id":21569201,"url":"https://github.com/awssat/array-helper","last_synced_at":"2025-07-24T21:05:09.370Z","repository":{"id":62490315,"uuid":"125334496","full_name":"awssat/array-helper","owner":"awssat","description":"🔗  A flexible, simple \u0026 yet powerful array manipulation helper for PHP.","archived":false,"fork":false,"pushed_at":"2018-03-17T15:40:13.000Z","size":11,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T12:47:51.518Z","etag":null,"topics":["array","array-filter","array-helper","array-manipulations","array-methods","array-processing","arrays","callback","chainable-methods","endif","loop","method-chaining","php"],"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/awssat.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":"2018-03-15T08:19:45.000Z","updated_at":"2022-12-07T13:18:29.000Z","dependencies_parsed_at":"2022-11-02T11:03:11.752Z","dependency_job_id":null,"html_url":"https://github.com/awssat/array-helper","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awssat%2Farray-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awssat%2Farray-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awssat%2Farray-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awssat%2Farray-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/awssat","download_url":"https://codeload.github.com/awssat/array-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248231895,"owners_count":21069423,"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","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","array-filter","array-helper","array-manipulations","array-methods","array-processing","arrays","callback","chainable-methods","endif","loop","method-chaining","php"],"created_at":"2024-11-24T11:07:23.209Z","updated_at":"2025-04-10T14:06:34.191Z","avatar_url":"https://github.com/awssat.png","language":"PHP","readme":"# array-helper\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/awssat/array-helper.svg?style=flat-square)](https://packagist.org/packages/awssat/array-helper)\n[![Build Status](https://img.shields.io/travis/awssat/array-helper/master.svg?style=flat-square)](https://travis-ci.org/awssat/array-helper)\n[![StyleCi Status](https://styleci.io/repos/125334496/shield)](https://styleci.io/repos/125334496)\n\n\n⚡️  A flexible, simple \u0026 yet powerful array manipulation helper for PHP. It gives you the magic of method chaining and it's easier and shorter to be included in views. It Supports most of [PHP built-in array functions](http://php.net/manual/en/book.array.php)\n\n\n```php\narr([' ', 'hi ', null, '  welcome'])-\u003emap('trim')-\u003efilter()-\u003eget()\n\u003e\u003e ['hi', 'welcome']\n```\n## Features\n- Support All PHP array functions.\n- Short methods names, no need to write \"array_\" like array_map can be only map(..)\n- Array items can be retrireve or updated as properties or keys  [-\u003ekey or [key] ]\n- Support powefull conditional methods. if, else, if{AnyMethod}, endif.\n- Support camelCase and snake-case methods name.\n- Useful new methods like equal, exists .. etc\n\n## Install/Use\nYou can install the package via composer locally in your project folder:\n\n```bash\n$ composer require awssat/array-helper\n```\n\nAfter installing it, just start using the helper `arr([...])` or `ArrayHelper::make([...])`\n\n## Examples\n\n\nUse any array function, no need for \"array_\", if you like it you can use it as in array_filter or arrayFilter .. all will work. \n```php \n$x = arr(['', 'item', null, 'item2'])-\u003efilter()-\u003eget()\n\u003e\u003e ['item', 'item2']\n```\n\nYou can use conditions, if(function() {...}), if{AnyMethod}, else(), endif()\n\n```php\n$x = arr(['item', 'item2', null])\n    -\u003eifContains(null)\n        -\u003efilter()\n    -\u003eendif()\n    -\u003eget()\n```\nyou may also use useful method with `if` like `ifEmpty`, `ifKeyExists` or `ifEqual` etc.\n\n\nget() will return all items, while get(index) return a item in the array. all() is alias for get(all, true) which will ignore conditions and force return of items anyway.\n\nThe example above can be shortened using all() like this:\n```php\n$x = arr(['item', 'item2', null])\n    -\u003eifContains(null)\n        -\u003efilter()\n    -\u003eall()\n```\n\nYou can use do(callback) to run a callback on the array.\n\n```php\n$x = arr(['item ', 'item2'])\n    -\u003edo(function() {\n        return $this-\u003emap('trim');\n    })\n    -\u003eall()\n```\n\n\nPHP built-in array_map, array_walk, array_filter, and array_reduce are the best! \n \n array_map to loop through all items and change them.\n```php \n$array-\u003emap(function($item) {\n         return 'Hello: '. strip_tags($item) . ' !'; \n    });\n```\nor for simple functions use, `$array-\u003emap('trim')`\n\narray_walk can be used for looping without changing items\n```php \n$array-\u003ewalk(function($item, $key) {\n            print \"$key: $item\u003cbr /\u003e\\n\";\n    });\n```\n\nor if you want to change the values \n```php\n$array-\u003ewalk(function(\u0026$item, $key) {\n            $item = $item * 2;\n        });\n```\n\narray_filter is great for filtering an array\n```php\n$array-\u003efilter(function($item) {\n            return $item \u003e 5;\n        });\n```\nor just `$array-\u003efilter()` to remove any value equal to FALSE.\n\n\n\n\n## Tests\nSimply use:\n```bash\n$ composer test\n```\n## Credits\n- [Abdulrahman M.](https://github.com/abdumu)\n- [All Contributors](../../contributors)\n\n## License\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawssat%2Farray-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fawssat%2Farray-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawssat%2Farray-helper/lists"}