{"id":14966353,"url":"https://github.com/yiisoft/arrays","last_synced_at":"2025-05-16T06:06:52.076Z","repository":{"id":34651226,"uuid":"182071753","full_name":"yiisoft/arrays","owner":"yiisoft","description":"Yii Array Helper","archived":false,"fork":false,"pushed_at":"2025-04-10T07:07:53.000Z","size":406,"stargazers_count":52,"open_issues_count":5,"forks_count":28,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-05-07T07:26:01.155Z","etag":null,"topics":["array","arrays","hacktoberfest","yii3"],"latest_commit_sha":null,"homepage":"https://www.yiiframework.com/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yiisoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"open_collective":"yiisoft","github":["yiisoft"]}},"created_at":"2019-04-18T11:01:58.000Z","updated_at":"2025-02-13T15:32:24.000Z","dependencies_parsed_at":"2024-04-17T04:44:06.246Z","dependency_job_id":"98450b40-8b3c-4449-aa62-9e0adf63f0be","html_url":"https://github.com/yiisoft/arrays","commit_stats":{"total_commits":187,"total_committers":31,"mean_commits":6.032258064516129,"dds":0.6363636363636364,"last_synced_commit":"cb102a3dd579055f322246ed50b29d90c95dccf3"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Farrays","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Farrays/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Farrays/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Farrays/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiisoft","download_url":"https://codeload.github.com/yiisoft/arrays/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254455275,"owners_count":22073943,"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","arrays","hacktoberfest","yii3"],"created_at":"2024-09-24T13:36:15.778Z","updated_at":"2025-05-16T06:06:51.993Z","avatar_url":"https://github.com/yiisoft.png","language":"PHP","funding_links":["https://opencollective.com/yiisoft","https://github.com/sponsors/yiisoft"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/yiisoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://yiisoft.github.io/docs/images/yii_logo.svg\" height=\"100px\" alt=\"Yii\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eYii Arrays\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\n[![Latest Stable Version](https://poser.pugx.org/yiisoft/arrays/v)](https://packagist.org/packages/yiisoft/arrays)\n[![Total Downloads](https://poser.pugx.org/yiisoft/arrays/downloads)](https://packagist.org/packages/yiisoft/arrays)\n[![Build status](https://github.com/yiisoft/arrays/actions/workflows/build.yml/badge.svg)](https://github.com/yiisoft/arrays/actions/workflows/build.yml)\n[![Code Coverage](https://codecov.io/gh/yiisoft/arrays/graph/badge.svg?token=SMTMNF4KT9)](https://codecov.io/gh/yiisoft/arrays)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Farrays%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/arrays/master)\n[![static analysis](https://github.com/yiisoft/arrays/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/arrays/actions?query=workflow%3A%22static+analysis%22)\n[![type-coverage](https://shepherd.dev/github/yiisoft/arrays/coverage.svg)](https://shepherd.dev/github/yiisoft/arrays)\n\nThe package provides:\n\n- `ArrayHelper` that has static methods to work with arrays;\n- `ArraySorter` that has static methods for sort arrays;\n- `ArrayAccessTrait` provides the implementation for\n  [\\IteratorAggregate](https://www.php.net/manual/class.iteratoraggregate),\n  [\\ArrayAccess](https://www.php.net/manual/class.arrayaccess) and\n  [\\Countable](https://www.php.net/manualn/class.countable.php);\n- `ArrayableInterface` and `ArrayableTrait` for use in classes who want to support customizable representation of their instances.\n\n## Requirements\n\n- PHP 8.1 or higher.\n\n## Installation\n\n```shell\ncomposer require yiisoft/arrays\n```\n\n## ArrayHelper usage\n\nArray helper methods are static so usage is like the following:\n\n```php\n$username = \\Yiisoft\\Arrays\\ArrayHelper::getValue($_POST, 'username');\n```\n\nOverall the helper has the following method groups.\n\n### Getting data\n\n- getValue\n- getValueByPath\n- getColumn\n- getObjectVars\n\n### Setting data\n\n- addValue\n- addValueByPath\n- setValue\n- setValueByPath\n\n### Removing data\n\n- remove\n- removeByPath\n- removeValue\n\n### Detecting array types\n\n- isIndexed\n- isAssociative\n\n### HTML encoding and decoding values\n\n- htmlDecode\n- htmlEncode\n\n### Testing against arrays\n\n- isIn\n- isSubset\n\n### Transformation\n\n- index\n- group\n- filter\n- map\n- merge\n- parametrizedMerge\n- renameKey\n- toArray\n\n### Other\n\n- keyExists\n- pathExists\n\n## ArraySorter usage\n\nArray sorter has one static method which usage is like the following:\n\n```php\n\\Yiisoft\\Arrays\\ArraySorter::multisort($data, ['age', 'name'], [SORT_ASC, SORT_DESC]);\n```\n\n## ArrayAccessTrait usage\n\n`ArrayAccessTrait` provides the implementation for\n[\\IteratorAggregate](https://www.php.net/manual/class.iteratoraggregate),\n[\\ArrayAccess](https://www.php.net/manual/class.arrayaccess) and\n[\\Countable](https://www.php.net/manualn/class.countable.php).\n\nNote that `ArrayAccessTrait` requires the class using it contain a property named `data` which should be an array.\nThe data will be exposed by ArrayAccessTrait to support accessing the class object like an array.\n\nExample of use:\n\n```php\nuse \\Yiisoft\\Arrays\\ArrayAccessTrait;\n\nclass OfficeClassification implements \\IteratorAggregate, \\ArrayAccess, \\Countable\n{\n    use ArrayAccessTrait;\n\n    public array $data = [\n        'a' =\u003e 'Class A',\n        'b' =\u003e 'Class B',\n        'c' =\u003e 'Class C',\n    ];\n}\n\n$classification = new OfficeClassification();\n\necho 'Count classes: ' . $classification-\u003ecount() . \"\\n\"; // 3\n\n$iterator = $classification-\u003egetIterator();\nwhile ($iterator-\u003evalid()) {\n    echo $iterator-\u003ecurrent() . \"\\n\"; // Class A, Class B, Class C\n    $iterator-\u003enext();\n}\n```\n\n## ArrayableInterface and ArrayableTrait usage\n\n`ArrayableInterface` and its implementation `ArrayableTrait` intended for use in classes who want to support customizable representation of their instances.\n\nExample of use:\n\n```php\nuse \\Yiisoft\\Arrays\\ArrayableTrait;\nuse \\Yiisoft\\Arrays\\ArrayableInterface;\n\nclass Car implements ArrayableInterface\n{\n    use ArrayableTrait;\n\n    public string $type = 'Crossover';\n    public string $color = 'Red';\n    public int $torque = 472;\n}\n\n$car = new Car();\n\n$data = $car-\u003etoArray(['type', 'color']); // ['type' =\u003e 'Crossover', 'color' =\u003e 'Red']\n```\n\n## Documentation\n\n- [Internals](docs/internals.md)\n\nIf you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.\nYou may also check out other [Yii Community Resources](https://www.yiiframework.com/community).\n\n## License\n\nThe Yii Arrays is free software. It is released under the terms of the BSD License.\nPlease see [`LICENSE`](./LICENSE.md) for more information.\n\nMaintained by [Yii Software](https://www.yiiframework.com/).\n\n## Support the project\n\n[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective\u0026logoColor=7eadf1\u0026labelColor=555555)](https://opencollective.com/yiisoft)\n\n## Follow updates\n\n[![Official website](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](https://www.yiiframework.com/)\n[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter\u0026logoColor=1DA1F2\u0026labelColor=555555?style=flat)](https://twitter.com/yiiframework)\n[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat\u0026logo=telegram)](https://t.me/yii3en)\n[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat\u0026logo=facebook\u0026logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)\n[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat\u0026logo=slack)](https://yiiframework.com/go/slack)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Farrays","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiisoft%2Farrays","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Farrays/lists"}