{"id":15026639,"url":"https://github.com/setnemo/asterisk-notation","last_synced_at":"2026-04-02T01:25:04.732Z","repository":{"id":46972730,"uuid":"394437096","full_name":"setnemo/asterisk-notation","owner":"setnemo","description":"Asterisk notation for array access in PHP","archived":false,"fork":false,"pushed_at":"2021-10-09T11:06:38.000Z","size":45,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-02T08:45:36.286Z","etag":null,"topics":["arrays","asterisk","asterisk-notation","hacktoberfest","notation","php","php74","php8"],"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/setnemo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-09T20:59:48.000Z","updated_at":"2024-07-27T07:42:43.000Z","dependencies_parsed_at":"2022-08-28T14:52:34.506Z","dependency_job_id":null,"html_url":"https://github.com/setnemo/asterisk-notation","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/setnemo/asterisk-notation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/setnemo%2Fasterisk-notation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/setnemo%2Fasterisk-notation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/setnemo%2Fasterisk-notation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/setnemo%2Fasterisk-notation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/setnemo","download_url":"https://codeload.github.com/setnemo/asterisk-notation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/setnemo%2Fasterisk-notation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31293810,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T01:05:07.454Z","status":"ssl_error","status_checked_at":"2026-04-02T00:56:46.496Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["arrays","asterisk","asterisk-notation","hacktoberfest","notation","php","php74","php8"],"created_at":"2024-09-24T20:04:49.485Z","updated_at":"2026-04-02T01:25:04.702Z","avatar_url":"https://github.com/setnemo.png","language":"PHP","readme":"# PHP Asterisk Notation\n\n[![Latest Stable Version](https://img.shields.io/github/v/release/setnemo/asterisk-notation)](https://github.com/setnemo/asterisk-notation/releases)\n\n[![Github actions Build](https://img.shields.io/github/workflow/status/setnemo/asterisk-notation/Tests)](//github.com/setnemo/asterisk-notation/actions)\n\n[![SonarCloud Coverage](https://sonarcloud.io/api/project_badges/measure?project=setnemo_asterisk-notation\u0026metric=coverage)](https://sonarcloud.io/component_measures/metric/coverage/list?id=setnemo_asterisk-notation)\n[![SonarCloud Reliability rating](https://sonarcloud.io/api/project_badges/measure?project=setnemo_asterisk-notation\u0026metric=reliability_rating)](https://sonarcloud.io/component_measures/metric/reliability_rating/list?id=setnemo_asterisk-notation)\n[![SonarCloud Security rating](https://sonarcloud.io/api/project_badges/measure?project=setnemo_asterisk-notation\u0026metric=security_rating)](https://sonarcloud.io/component_measures/metric/security_rating/list?id=setnemo_asterisk-notation)\n[![SonarCloud Bugs](https://sonarcloud.io/api/project_badges/measure?project=setnemo_asterisk-notation\u0026metric=bugs)](https://sonarcloud.io/component_measures/metric/bugs/list?id=setnemo_asterisk-notation)\n[![SonarCloud Code Smells](https://sonarcloud.io/api/project_badges/measure?project=setnemo_asterisk-notation\u0026metric=code_smells)](https://sonarcloud.io/component_measures/metric/code_smells/list?id=setnemo_asterisk-notation)\n\n[![Github License](https://img.shields.io/github/license/setnemo/asterisk-notation.svg)](https://packagist.org/packages/setnemo/asterisk-notation)\n\nAsterisk notation for array access in PHP. Update array access to the next level of usability.\n\n## Asterisk notation\n\n```php\nuse Setnemo\\Asterisk;\n\n$items = new Asterisk([\n    'Europe' =\u003e [\n        'Ukraine' =\u003e [\n            'capital' =\u003e 'Kyiv',\n            'currency' =\u003e 'UAH'\n        ],\n        'Poland' =\u003e [\n            'capital' =\u003e 'Warsaw',\n            'currency' =\u003e 'PLN'\n        ],\n\n    ],\n    'Africa' =\u003e [\n        'South Africa' =\u003e [\n            'capital' =\u003e 'Capetown',\n            'currency' =\u003e 'ZAR'\n        ],\n        'Nigeria' =\u003e [\n            'capital' =\u003e 'Abuja',\n            'currency' =\u003e 'NGN'\n        ],\n    ],\n]);\n$city = 'Kyiv';\n$resultTrue = $items-\u003ehas('*.*.capital', $city);\n$resultFalse = $items-\u003ehas('Africa.*.capital', $city);\nif ($resultTrue === true \u0026\u0026 $resultFalse === false) {\n    echo \"Wow! It works correctly!\";\n}\n```\n\n## Install\n\nInstall the latest version using Composer:\n\n```bash\ncomposer require setnemo/asterisk-notation\n```\n\n## Usage\n\nCreate a new \\Setnemo\\Asterisk object:\n\n```php\nuse Adbar\\Dot;\nuse Setnemo\\Asterisk;\n$asterisk = new Asterisk;\n$array = ['first_one' =\u003e ['second' =\u003e 'value'], 'first_two' =\u003e ['second' =\u003e 'value'],];\n// With existing array\n$asterisk = new Asterisk($array);\n// With existing \\Adbar\\Dot\n$dot = new Dot($array);\n$asterisk = new Asterisk($dot);\n// or existing Asterisk\n$newAsterisk = new Asterisk($asterisk);\n```\n\n## Methods\n\nAsterisk has the following methods:\n\n- [add()](#add)\n- [all()](#all)\n- [clear()](#clear)\n- [count()](#count)\n- [delete()](#delete)\n- [flatten()](#flatten)\n- [get()](#get)\n- [has()](#has)\n- [isEmpty()](#isempty)\n- [merge()](#merge)\n- [mergeRecursive()](#mergerecursive)\n- [mergeRecursiveDistinct()](#mergerecursivedistinct)\n- [pull()](#pull)\n- [push()](#push)\n- [replace()](#replace) // use Dot::replace(), **need write tests**, because used get(), set()\n- [set()](#set)\n- [setArray()](#setarray)\n- [setReference()](#setreference)\n- [toJson()](#tojson) // use Dot::toJson(), **need write tests**, because used get()\n\n\u003ca name=\"add\"\u003e\u003c/a\u003e\n### add()\n\nUsing for adding element with asterisk in key\n\u003e Work like [Adbar\\Dot::add()](https://github.com/adbario/php-dot-notation#add)\n\n\u003ca name=\"all\"\u003e\u003c/a\u003e\n### all()\n\n\u003e Work like [Adbar\\Dot::all()](https://github.com/adbario/php-dot-notation#all)\n\n\u003ca name=\"clear\"\u003e\u003c/a\u003e\n### clear()\n\nDeletes the contents of a given key (sets an empty array):\n```php\n$asterisk-\u003eclear('department.*.write_rules');\n\n// Equivalent vanilla PHP\n$array['department']['project1']['write_rules'] = [];\n$array['department']['project2']['write_rules'] = [];\n$array['department']['projectN']['write_rules'] = [];\n```\n\nMultiple keys:\n```php\n$asterisk-\u003eclear(['department.*.write_rules', 'department.*.read_rules']);\n```\n\nAll the stored items:\n```php\n$asterisk-\u003eclear();\n\n// Equivalent vanilla PHP\n$array = [];\n```\n\n\u003e If key not contains * (asterisk) - it works like [Adbar\\Dot::clear()](https://github.com/adbario/php-dot-notation#clear)\n\n\u003ca name=\"count\"\u003e\u003c/a\u003e\n### count()\n\nReturns the number of items in a given key:\n```php\n$asterisk-\u003ecount('user.siblings');\n```\n\nItems in the root of Dot object:\n```php\n$asterisk-\u003ecount();\n\n// Or use count() function as Dot implements Countable\ncount($asterisk);\n```\n\u003e If key not contains * (asterisk) - it works like [Adbar\\Dot::count()](https://github.com/adbario/php-dot-notation#count)\n\n\n\u003ca name=\"delete\"\u003e\u003c/a\u003e\n### delete()\n\nDeletes the given key:\n```php\n$asterisk-\u003edelete('*.name');\n\n// ArrayAccess\nunset($asterisk['user1.name']);\nunset($asterisk['user2.name']);\n\n// Equivalent vanilla PHP\nunset($array['user1']['name']);\nunset($array['user2']['name']);\n```\n\nMultiple keys:\n```php\n$asterisk-\u003edelete([\n    '*.name',\n    '*.title'\n]);\n```\n\n\u003ca name=\"flatten\"\u003e\u003c/a\u003e\n### flatten()\n\n\u003e It works like [Adbar\\Dot::flatten()](https://github.com/adbario/php-dot-notation#flatten)\n\n\u003ca name=\"get\"\u003e\u003c/a\u003e\n### get()\n\nReturns the value of a given key:\n```php\n$result = $asterisk-\u003eget('*.name'));\n\n// ArrayAccess\n$result['user1.name'] = $asterisk['user1.name'];\n$result['user2.name'] = $asterisk['user2.name'];\n\n// Equivalent vanilla PHP \nif (isset($array['user1']['name']) {\n    $result['user1.name'] = $array['user1']['name'];\n}\nif (isset($array['user1']['name']) {\n    $result['user2.name'] = $array['user2']['name'];\n}\n\n```\n\nReturns a given default value, if the given key doesn't exist:\n```php\necho $asterisk-\u003eget('user.name', 'some default value');\n```\n\u003e Default value not work with asterisk\n\n\u003ca name=\"has\"\u003e\u003c/a\u003e\n### has()\n\nChecks if a given key exists (returns boolean true or false):\n```php\n$asterisk-\u003ehas('user.name');\n\n// ArrayAccess\nisset($asterisk['user.name']);\n```\n\nMultiple keys:\n```php\n$asterisk-\u003ehas([\n    'user.name',\n    'page.title'\n]);\n```\n\nWith asterisk:\n```php\n$asterisk = new \\Setnemo\\Asterisk(['1' =\u003e ['second' =\u003e 'value'],'2' =\u003e ['second' =\u003e 'value']]);\n$asterisk-\u003ehas('*.second'); // true\n$asterisk = new \\Setnemo\\Asterisk(['1' =\u003e ['first' =\u003e ['test' =\u003e 42]],'2' =\u003e ['second' =\u003e 'value'],'3' =\u003e ['third' =\u003e ['value' =\u003e 42]]]);\n$asterisk-\u003ehas('*.*.value'); // true\n$asterisk = new \\Setnemo\\Asterisk(['user1' =\u003e ['name' =\u003e 'John', 'job' =\u003e 'warrior'], 'user2' =\u003e ['name' =\u003e 'Robin', 'job' =\u003e 'archer']);\n$asterisk-\u003ehas('*.spouse'); // false\n```\n\nWith asterisk and value:\n```php\n$asterisk = new \\Setnemo\\Asterisk([]);\n$asterisk-\u003ehas('*', false); // false\n$asterisk = new \\Setnemo\\Asterisk(['*' =\u003e ['second' =\u003e 'VALUE']]);\n$asterisk-\u003ehas('*.second', 'VALUE'); // true\n$asterisk-\u003ehas('*.second', 'value'); // false because lowercase\n$asterisk = new \\Setnemo\\Asterisk(['*' =\u003e ['second' =\u003e 'value'], 0 =\u003e [0 =\u003e 0], 11 =\u003e 11]);\n$asterisk-\u003ehas('*.11', 11); // true\n$asterisk = new \\Setnemo\\Asterisk(['1' =\u003e ['second' =\u003e 'value'],'2' =\u003e ['second' =\u003e '-']]);\n$asterisk-\u003ehas('*.second', 'value'); // false because 'second' =\u003e '-'\n$asterisk = new \\Setnemo\\Asterisk(['1' =\u003e ['second' =\u003e 'value'],'2' =\u003e ['second' =\u003e 'value']]);\n$asterisk-\u003ehas('*.second', 'value'); // true\n```\nWith asterisk and value (non-strict mode):\n```php\n$asterisk = new \\Setnemo\\Asterisk([\n'locations' =\u003e [\n    'Europe' =\u003e [\n        'Ukraine' =\u003e [\n            'capital' =\u003e 'Kyiv',\n            'currency' =\u003e 'UAH'\n        ],\n        'Poland' =\u003e [\n            'capital' =\u003e 'Warsaw',\n            'currency' =\u003e 'PLN'\n        ],\n\n    ],\n    'Africa' =\u003e [\n        'South Africa' =\u003e [\n            'capital' =\u003e 'Capetown',\n            'currency' =\u003e 'ZAR'\n        ],\n        'Nigeria' =\u003e [\n            'capital' =\u003e 'Abuja',\n            'currency' =\u003e 'NGN'\n        ],\n    ],\n]]);\n// third parameter is false for non-strict mode\n$asterisk-\u003ehas('locations.*.*.capital', 'Kyiv', false); // true\n$asterisk-\u003ehas('locations.*.*.currency', 'ZAR', false); // true\n$asterisk-\u003ehas('locations.Europe.*.currency', 'ZAR', false); // false\n```\n\n\u003ca name=\"isempty\"\u003e\u003c/a\u003e\n### isEmpty()\n\nChecks if a given key is empty (returns boolean true or false):\n```php\n$asterisk-\u003eisEmpty('user.name');\n\n// ArrayAccess\nempty($asterisk['user.name']);\n\n// Equivalent vanilla PHP\nempty($array['user']['name']);\n```\n\nMultiple keys:\n```php\n$asterisk-\u003eisEmpty([\n    'user.name',\n    'page.title'\n]);\n```\n\nChecks the whole Asterisk object:\n```php\n$asterisk-\u003eisEmpty();\n```\n\nAlso works with asterisk in key:\n```php\n$asterisk = new \\Setnemo\\Asterisk(['user1' =\u003e ['name' =\u003e 'John'], 'user2' =\u003e ['name' =\u003e 'Robin']);\n$asterisk-\u003eisEmpty('*.name'); // false\n$asterisk-\u003eisEmpty('*.spouse'); // true\n```\n\n\u003ca name=\"merge\"\u003e\u003c/a\u003e\n### merge()\n\n\u003e It works like [Adbar\\Dot::merge()](https://github.com/adbario/php-dot-notation#merge)\n\u003e Asterisk in path Asterisk::merge('key', 'value') work like Asterisk::set('key', 'value', false)\n\n\u003ca name=\"mergerecursive\"\u003e\u003c/a\u003e\n### mergeRecursive()\n\n\u003e It works like [Adbar\\Dot::mergeRecursive()](https://github.com/adbario/php-dot-notation#mergeRecursive)\n\u003e Asterisk in path Asterisk::mergeRecursive('key', 'value') work like Asterisk::set('key', 'value', false)\n\n\u003ca name=\"mergerecursivedistinct\"\u003e\u003c/a\u003e\n### mergeRecursiveDistinct()\n\n\u003e It works like [Adbar\\Dot::mergeRecursiveDistinct()](https://github.com/adbario/php-dot-notation#mergeRecursiveDistinct)\n\n\u003ca name=\"pull\"\u003e\u003c/a\u003e\n### pull()\n\nReturns the value of a given key and deletes the key:\n```php\necho $asterisk-\u003epull('user.name');\n\n// Equivalent vanilla PHP \u003c 7.0\necho isset($array['user']['name']) ? $array['user']['name'] : null;\nunset($array['user']['name']);\n\n// Equivalent vanilla PHP \u003e= 7.0\necho $array['user']['name'] ?? null;\nunset($array['user']['name']);\n```\n\nReturns a given default value, if the given key doesn't exist:\n```php\necho $asterisk-\u003epull('user.name', 'some default value');\n```\n\u003e Default value not work with asterisk in query!\n\nReturns all the stored items as an array and clears the Dot object:\n```php\n$items = $asterisk-\u003epull();\n```\n\nKey with asterisk:\n```php\n$asterisk = new \\Setnemo\\Asterisk([['user1' =\u003e ['name' =\u003e 'John', 'job' =\u003e 'warrior'], 'user2' =\u003e ['name' =\u003e 'Robin', 'job' =\u003e 'archer'],]]);\n$result = $asterisk-\u003epull('*.name'); // ['user1.name' =\u003e 'John', 'user2.name' =\u003e 'Robin']\n$all = $asterisk-\u003eall(); // ['user1' =\u003e ['job' =\u003e 'warrior'], 'user2' =\u003e ['job' =\u003e 'archer'],]\n \n```\n\u003ca name=\"push\"\u003e\u003c/a\u003e\n### push()\n\nPushes a given value to the end of the array in a given key:\n```php\n$asterisk-\u003epush('users', 'John');\n\n// Equivalent vanilla PHP\n$array['users'][] = 'John';\n```\n\nPushes a given value to the end of the array:\n```php\n$asterisk-\u003epush('John');\n\n// Equivalent vanilla PHP\n$array[] = 'John';\n```\n\nWith asterisk:\n```php\n$asterisk = new \\Setnemo\\Asterisk([\n    'first_one' =\u003e ['second' =\u003e 'value'],\n    'first_two' =\u003e ['second' =\u003e 'value']\n]);\n$asterisk-\u003epush('*.second', 'John');\n\n$asterisk-\u003eall();\n/*\n[\n    'first_one' =\u003e ['second' =\u003e ['value','VALUE']],\n    'first_two' =\u003e ['second' =\u003e ['value','VALUE']]\n]\n */\n```\n\nAlso work as Asterisk::set('key', 'value', true), where true is asterisk boolean.\nSee [Asterisk::set()](#set)\n\n\n\u003ca name=\"replace\"\u003e\u003c/a\u003e\n### replace()\n\n\u003e It works like [Adbar\\Dot::replace()](https://github.com/adbario/php-dot-notation#replace)\n\n\u003ca name=\"set\"\u003e\u003c/a\u003e\n### set()\n\nSets a given key / value pair:\n```php\n$asterisk-\u003eset('user.name', 'John');\n\n// ArrayAccess\n$asterisk['user.name'] = 'John';\n\n// Equivalent vanilla PHP\n$array['user']['name'] = 'John';\n```\n\nMultiple key / value pairs:\n```php\n$asterisk-\u003eset([\n    'user.name' =\u003e 'John',\n    'page.title'     =\u003e 'Home'\n]);\n```\n\n\u003ca name=\"setarray\"\u003e\u003c/a\u003e\n### setArray()\n\n\u003e It works like [Adbar\\Dot::setarray()](https://github.com/adbario/php-dot-notation#setarray)\n\n\u003ca name=\"setreference\"\u003e\u003c/a\u003e\n### setReference()\n\n\u003e It works like [Adbar\\Dot::setreference()](https://github.com/adbario/php-dot-notation#setreference)\n\n\u003ca name=\"tojson\"\u003e\u003c/a\u003e\n### toJson()\n\n\u003e It works like [Adbar\\Dot::toJson()](https://github.com/adbario/php-dot-notation#toJson)\n\n\n## License\n\n[MIT license](LICENSE.txt)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsetnemo%2Fasterisk-notation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsetnemo%2Fasterisk-notation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsetnemo%2Fasterisk-notation/lists"}