{"id":22092114,"url":"https://github.com/krakphp/array","last_synced_at":"2025-07-29T07:35:02.208Z","repository":{"id":57009006,"uuid":"78256042","full_name":"krakphp/array","owner":"krakphp","description":"Missing PHP Array Utilities","archived":false,"fork":false,"pushed_at":"2017-12-19T03:47:37.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T23:45:14.374Z","etag":null,"topics":[],"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/krakphp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-07T03:26:52.000Z","updated_at":"2017-02-26T23:18:25.000Z","dependencies_parsed_at":"2022-08-21T14:50:50.837Z","dependency_job_id":null,"html_url":"https://github.com/krakphp/array","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/krakphp/array","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Farray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Farray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Farray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Farray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krakphp","download_url":"https://codeload.github.com/krakphp/array/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Farray/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267646452,"owners_count":24121022,"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-29T02:00:12.549Z","response_time":2574,"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-12-01T03:08:22.200Z","updated_at":"2025-07-29T07:35:02.178Z","avatar_url":"https://github.com/krakphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Array\n\nThe array library is just a simple collection of missing php array functions.\n\n## Installation\n\nInstall with composer at `krak/array`\n\n## Usage\n\n```php\n\u003c?php\n\nuse Krak\\Arr;\n\n$data = [\n    'a' =\u003e [\n        'b' =\u003e 1,\n    ],\n];\n\n$res = Arr\\get($data, 'a.b');\nassert($res == 1);\n\nArr\\set($data, 'c.d', 2);\nassert($data['c']['d'] == 2);\n\n// or use the global aliases\narray_get($data, 'a.b');\n```\n\nThere also is a `Bag` class which provides an object oriented API for the arrays.\n\n```php\n\u003c?php\n\nuse Krak\\Arr;\n\n$bag = new Arr\\Bag();\n$bag-\u003eset('a.b', 1);\nvar_dump($bag-\u003eraw());\n/*\n    array(1) {\n      [\"a\"]=\u003e\n      array(1) {\n        [\"b\"]=\u003e\n        int(1)\n      }\n    }\n*/\n```\n\n## API\n\nThe following are defined in the namespace `Krak\\Arr`:\n\n    array expand(iterable $iterable, string $separator = '.')\n    array index_by(iterable $iterable, string $key)\n    array udiff_stable(iterable $a, iterable $b, callable $cmp)\n    mixed get(array $data, string $key, mixed $else = null)\n    mixed getIn(array $data, array $key, mixed $else = null);\n    bool has(array $data, string $key, string $sep = '.')\n    bool hasIn(array $data, array $key)\n    void set(array \u0026$data, string $key, mixed $value, string $sep = '.')\n    void del(array \u0026$data, string $key, string $sep = '.')\n\nYou can also use the globally defined aliases\n\n    array_expand\n    array_index_by\n    array_udiff_stable\n    array_get\n    array_has\n    array_set\n    array_del\n\nOr the `Krak\\Arr\\Bag` class:\n\n```php\n\u003c?php\n\nnamespace Krak\\Arr;\n\nclass Bag implements ArrayAccess {\n    public function __construct(array $data = [])\n    public function get($key, $else = null, $sep = '.')\n    public function getIn(array $key, $else = null)\n    public function set($key, $value, $sep = '.')\n    public function has($key, $sep = '.')\n    public function hasIn(array $key)\n    public function del($key, $sep = '.')\n    public function raw()\n}\n```\n\n## Tests\n\nRun tests with `phpunit`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakphp%2Farray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrakphp%2Farray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakphp%2Farray/lists"}