{"id":36399970,"url":"https://github.com/jonnyynnoj/dot","last_synced_at":"2026-01-11T16:03:03.292Z","repository":{"id":57028213,"uuid":"258225442","full_name":"jonnyynnoj/dot","owner":"jonnyynnoj","description":"Use dot notation to access nested array keys and/or object properties","archived":false,"fork":false,"pushed_at":"2025-10-16T09:46:08.000Z","size":100,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-26T10:43:02.875Z","etag":null,"topics":["dot-notation","dotnotation","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/jonnyynnoj.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":"2020-04-23T14:05:20.000Z","updated_at":"2025-10-15T17:38:23.000Z","dependencies_parsed_at":"2022-08-23T16:20:27.190Z","dependency_job_id":null,"html_url":"https://github.com/jonnyynnoj/dot","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/jonnyynnoj/dot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonnyynnoj%2Fdot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonnyynnoj%2Fdot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonnyynnoj%2Fdot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonnyynnoj%2Fdot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonnyynnoj","download_url":"https://codeload.github.com/jonnyynnoj/dot/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonnyynnoj%2Fdot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28312216,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T14:58:17.114Z","status":"ssl_error","status_checked_at":"2026-01-11T14:55:53.580Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["dot-notation","dotnotation","php"],"created_at":"2026-01-11T16:03:02.537Z","updated_at":"2026-01-11T16:03:03.288Z","avatar_url":"https://github.com/jonnyynnoj.png","language":"PHP","readme":"# Dot\n\n[![Travis (.com)](https://img.shields.io/travis/com/jonnyynnoj/dot?style=flat-square)](https://travis-ci.com/github/jonnyynnoj/dot)\n[![Latest Stable Version](https://poser.pugx.org/noj/dot/v/stable?format=flat-square)](https://packagist.org/packages/noj/dot)\n![PHP Version Support](https://img.shields.io/packagist/php-v/noj/dot?style=flat-square)\n[![License](https://poser.pugx.org/noj/dot/license?format=flat-square)](https://packagist.org/packages/noj/dot)\n[![Total Downloads](https://poser.pugx.org/noj/dot/downloads?format=flat-square)](https://packagist.org/packages/noj/dot)\n\nDot allows you to get \u0026 set array keys or object properties using dot notation.\n\n## Installing\n\n```bash\ncomposer require noj/dot\n```\n\n## Usage\n\nFirst construct a new Dot instance:\n\n```php\n$dot = new Dot($data);\n$dot = Dot::from($data); // alternative\n```\n\nAll the examples are using the following data structure unless otherwise specified:\n\n```php\n$data = [\n    'groups' =\u003e [\n        (object)[\n            'name' =\u003e 'group1',\n            'items' =\u003e [\n                [\n                    'name' =\u003e 'item1',\n                    'rare' =\u003e false,\n                ],\n                [\n                    'name' =\u003e 'item3',\n                    'rare' =\u003e true,\n                ],\n            ]\n        ],\n        (object)[\n            'name' =\u003e 'group2',\n            'items' =\u003e []\n        ],\n        (object)[\n            'name' =\u003e 'group3',\n            'items' =\u003e [\n                [\n                    'name' =\u003e 'item2',\n                    'rare' =\u003e true,\n                ],\n            ]\n        ],\n    ]\n];\n```\n\n### Methods\n\n- [count](#dotcountstring-path-int)\n- [find](#dotfindstring-path-mixed-equals-dot)\n- [first](#dotfirststring-path-mixed-equals-dot)\n- [get](#dotgetnullintstring-path-mixed)\n- [has](#dothasstring-path-bool)\n- [push](#dotpushstring-path-mixed-value-dot)\n- [set](#dotsetarraystring-paths-mixed-value-void)\n\n#### `Dot::count(string $path): int`\n\nCount the number of items at a given path.\n```php\n$dot-\u003ecount('groups.0.items'); // 2\n$dot-\u003ecount('groups.*.items'); // 3\n```\n\n#### `Dot::find(string $path, mixed $equals): Dot`\n\nFind items that pass the given truth test.\n\n```php\n// find where property === value\n$dot-\u003efind('groups.*.items.*.rare', true)-\u003eget();\n/*\n[\n    ['name' =\u003e 'item3', 'rare' =\u003e true],\n    ['name' =\u003e 'item2', 'rare' =\u003e true],\n]\n*/\n\n// pass a callback for custom comparisons \n$dot-\u003efind('groups.*.items.*.name', function (string $name) {\n    return $name === 'item2' || $name === 'item3';\n})-\u003eget(); // returns same as above\n\n// leave off the property to receive the whole item\n$dot-\u003efind('groups.*.items.*', function (array $item) {\n    return $item['name'] === 'item3' \u0026\u0026 $item['rare'];\n})-\u003eget();\n```\n\n#### `Dot::first(string $path, mixed $equals): Dot`\n\nFind the first item that passes the given truth test.\n\n```php\n$dot-\u003efirst('groups.*.items.*.rare', true)-\u003eget(); // ['name' =\u003e 'item3', 'rare' =\u003e true]\n\n$dot-\u003efirst('groups.*.items.*', fn (array $item) =\u003e $item['rare'] === true)-\u003eget(); // same as above\n```\n\n#### `Dot::get(null|int|string $path): mixed`\n\nAccess nested array keys and object properties using dot syntax:\n\n```php\n$dot-\u003eget('groups.0.items.1.name'); // 'item3'\n```\n\nDot safely returns null if the key or property doesn't exist:\n\n```php\n$dot-\u003eget('groups.3.items.1.name'); // null\n```\n\nYou can use a wildcard `*` to pluck values from multiple paths:\n\n```php\n$dot-\u003eget('groups.*.items.*.name'); // ['item1', 'item3', 'item2']\n\n$dot-\u003eget('groups.*.items'); /* [\n    ['name' =\u003e 'item1', 'rare' =\u003e false],\n    ['name' =\u003e 'item3', 'rare' =\u003e true],\n    ['name' =\u003e 'item2', 'rare' =\u003e true],\n] */\n```\n\nYou can call functions using the `@` prefix:\n\n```php\n$data = [\n    'foo' =\u003e new class {\n        public function getBar() {\n            return ['bar' =\u003e 'value'];\n        }\n    }\n];\n\n(new Dot($data))-\u003eget('foo.@getBar.bar'); // 'value'\n```\n\nIf no argument is passed it will return the underlying data:\n\n```php\n$dot-\u003eget() === $data; // true\n```\n\n#### `Dot::has(string $path): bool`\n\nReturns true if path exists, false otherwise:\n\n```php\n$dot-\u003ehas('groups.0.items.1.name'); // true\n```\n\n#### `Dot::push(string $path, mixed $value): Dot`\n\nPush a value onto an existing array:\n\n```php\n$dot-\u003epush('groups.0.items', ['name' =\u003e 'another item']);\n\n// supports wildcards\n$dot-\u003epush('groups.*.items', ['name' =\u003e 'another item']);\n```\n\n#### `Dot::set(array|string $paths, mixed $value): void`\n\nYou can set nested values using the same syntax:\n\n```php\n$dot-\u003eset('groups.2.items.0.name', 'a different name');\necho $data['groups'][2]-\u003eitems[0]['name']; // 'a different name'\n```\n\nSet nested keys from multiple paths using a wildcard `*`:\n\n```php\n$dot-\u003eset('groups.*.items.*.name', 'set all to same name');\n```\n\nKeys will be created if they don't already exist:\n\n```php\n$dot-\u003eset('groups.0.items.2.name', 'a new item');\n```\n\nBy default, set will initialise missing values as empty arrays. To indicate that something should be an object use the `-\u003e` delimiter:\n```php\n$dot-\u003eset('groups.3-\u003eitems.2.name', 'a new item');\n```\n\nYou can set multiple values at once by passing an array:\n\n```php\n$dot-\u003eset([\n    'groups.0.items.1.name' =\u003e 'something',\n    'groups.2.items.0.name' =\u003e 'something else',\n]):\n```\n\nYou can call a method:\n\n```php\n$data = [\n    'foo' =\u003e new class {\n        public $bars = [];\n        public function addBar($bar) {\n            $this-\u003ebar[] = $bar;\n        }\n    }\n];\n\n$dot = new Dot($data);\n$dot-\u003eset('foo.@addBar', 'value');\necho $data['foo']-\u003ebars; // ['value']\n```\n\nOr call a method for each value of an array:\n\n```php\n$dot-\u003eset('foo.@addBar*', ['value1', 'value2']);\necho $data['foo']-\u003ebars; // ['value1', 'value2']\n```\n\n### Non-chained versions\n\nAll methods have non-chained versions of themselves as a standalone function, i.e:\n\n```php\n// instead of\n$filtered = \\Noj\\Dot\\Dot::from($data)\n    -\u003efind('groups.*.items.*.rare', true)\n    -\u003eget();\n\n// you can do\n$filtered = \\Noj\\Dot\\find($data, 'groups.*.items.*.rare', true');\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonnyynnoj%2Fdot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonnyynnoj%2Fdot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonnyynnoj%2Fdot/lists"}