{"id":21874564,"url":"https://github.com/smoren/array-view-php","last_synced_at":"2025-04-15T01:24:15.111Z","repository":{"id":226831834,"uuid":"769749892","full_name":"Smoren/array-view-php","owner":"Smoren","description":"Create array views for easy data manipulation, select elements using Python-like slice notation, enable efficient selection of elements using index lists and boolean masks.","archived":false,"fork":false,"pushed_at":"2024-12-18T21:43:25.000Z","size":937,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T13:21:13.865Z","etag":null,"topics":["array","array-view","array-viewer","good-first-issue","mask","python-like","selector","slice","view"],"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/Smoren.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-03-10T00:10:50.000Z","updated_at":"2024-12-18T21:43:28.000Z","dependencies_parsed_at":"2024-03-24T01:27:27.305Z","dependency_job_id":"01ffb487-6177-4c8e-8765-dcc20c921337","html_url":"https://github.com/Smoren/array-view-php","commit_stats":null,"previous_names":["smoren/array-view-php"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Smoren%2Farray-view-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Smoren%2Farray-view-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Smoren%2Farray-view-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Smoren%2Farray-view-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Smoren","download_url":"https://codeload.github.com/Smoren/array-view-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248986872,"owners_count":21194135,"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-view","array-viewer","good-first-issue","mask","python-like","selector","slice","view"],"created_at":"2024-11-28T07:12:44.115Z","updated_at":"2025-04-15T01:24:15.098Z","avatar_url":"https://github.com/Smoren.png","language":"PHP","readme":"# Array View PHP\n![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/smoren/array-view)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Smoren/array-view-php/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Smoren/array-view-php/?branch=master)\n[![Coverage Status](https://coveralls.io/repos/github/Smoren/array-view-php/badge.svg?branch=master)](https://coveralls.io/github/Smoren/array-view-php?branch=master)\n![Build and test](https://github.com/Smoren/array-view-php/actions/workflows/test.yml/badge.svg)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n![Array View Logo](docs/images/logo.png)\n\n**Array View** is a PHP library that provides powerful abstractions and utilities for working with lists of data.\nCreate views of arrays, slice and index using Python-like notation, transform and select your data using chained and\nfluent operations.\n\n## Features\n- Array views as an abstraction over an array\n- Forward and backward array indexing\n- Selecting and slicing using [Python-like slice notation](https://www.geeksforgeeks.org/python-list-slicing/)\n- Filtering, mapping, matching and masking\n- Chaining operations via pipes and fluent interfaces\n\n## How to install to your project\n```bash\ncomposer require smoren/array-view\n```\n\n## Usage\n### Indexing\n\nIndex into an array forward or backwards using positive or negative indexes.\n\n| Data             |   1  |   2  |   3  |   4  |   5  |   6  |   7  |\n| ---------------- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |\n| *Positive Index* |  *0* |  *1* |  *2* | *3*  |  *4* |  *5* |  *6* |\n| *Negative Index* | *-7* | *-6* | *-5* | *-4* | *-3* | *-2* | *-1* |\n```php\nuse Smoren\\ArrayView\\Views\\ArrayView;\n\n$view = ArrayView::toView([1, 2, 3, 4, 5, 6, 7]);\n\n$view[0];  // 1\n$view[1];  // 2\n$view[-1]; // 7\n$view[-2]; // 6\n```\n\n### Slices\n\nUse [Python-like slice notation](https://www.geeksforgeeks.org/python-list-slicing/) to select a range of elements: `[start, stop, step]`.\n```php\nuse Smoren\\ArrayView\\Views\\ArrayView;\n\n$originalArray = [1, 2, 3, 4, 5, 6, 7, 8, 9];\n$view = ArrayView::toView($originalArray);\n\n$view['1:6'];   // [2, 3, 4, 5, 6]\n$view['1:7:2']; // [2, 4, 6]\n$view[':3'];    // [1, 2, 3]\n$view['::-1'];  // [9, 8, 7, 6, 5, 4, 3, 2, 1]\n```\n\nInsert into parts of the array.\n```php\n$view['1:7:2'] = [22, 44, 66];\nprint_r($originalArray); // [1, 22, 3, 44, 5, 66, 7, 8, 9]\n```\n\n### Subviews\n\nCreate subviews of the original view using masks, indexes, and slices.\n```php\nuse Smoren\\ArrayView\\Selectors\\IndexListSelector;\nuse Smoren\\ArrayView\\Selectors\\MaskSelector;\nuse Smoren\\ArrayView\\Selectors\\SliceSelector;\nuse Smoren\\ArrayView\\Views\\ArrayView;\n\n$originalArray = [1, 2, 3, 4, 5];\n$view = ArrayView::toView($originalArray);\n\n// Object-oriented style\n$view-\u003esubview(new MaskSelector([true, false, true, false, true]))-\u003etoArray(); // [1, 3, 5]\n$view-\u003esubview(new IndexListSelector([1, 2, 4]))-\u003etoArray();                   // [2, 3, 5]\n$view-\u003esubview(new SliceSelector('::-1'))-\u003etoArray();                          // [5, 4, 3, 2, 1]\n\n// Scripting style \n$view-\u003esubview([true, false, true, false, true])-\u003etoArray(); // [1, 3, 5]\n$view-\u003esubview([1, 2, 4])-\u003etoArray();                        // [2, 3, 5]\n$view-\u003esubview('::-1')-\u003etoArray();                           // [5, 4, 3, 2, 1]\n\n$view-\u003esubview(new MaskSelector([true, false, true, false, true]))-\u003eapply(fn ($x) =\u003e x * 10);\nprint_r($originalArray); // [10, 2, 30, 4, 50]\n```\n\n### Subarray Multi-indexing\n\nDirectly select multiple elements using an array-index multi-selection.\n```php\nuse Smoren\\ArrayView\\Selectors\\IndexListSelector;\nuse Smoren\\ArrayView\\Selectors\\MaskSelector;\nuse Smoren\\ArrayView\\Selectors\\SliceSelector;\nuse Smoren\\ArrayView\\Views\\ArrayView;\n\n$originalArray = [1, 2, 3, 4, 5];\n$view = ArrayView::toView($originalArray);\n\n// Object-oriented style\n$view[new MaskSelector([true, false, true, false, true])]; // [1, 3, 5]\n$view[new IndexListSelector([1, 2, 4])];                   // [2, 3, 5]\n$view[new SliceSelector('::-1')];                          // [5, 4, 3, 2, 1]\n\n// Scripting style\n$view[[true, false, true, false, true]]; // [1, 3, 5]\n$view[[1, 2, 4]];                        // [2, 3, 5]\n$view['::-1'];                           // [5, 4, 3, 2, 1]\n\n$view[new MaskSelector([true, false, true, false, true])] = [10, 30, 50];\nprint_r($originalArray); // [10, 2, 30, 4, 50]\n```\n\n### Combining Subviews\n\nCombine and chain subviews one after another in a fluent interface to perform multiple selection operations.\n```php\nuse Smoren\\ArrayView\\Selectors\\IndexListSelector;\nuse Smoren\\ArrayView\\Selectors\\MaskSelector;\nuse Smoren\\ArrayView\\Selectors\\SliceSelector;\nuse Smoren\\ArrayView\\Views\\ArrayView;\n\n$originalArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n\n// Fluent object-oriented style\n$subview = ArrayView::toView($originalArray)\n    -\u003esubview(new SliceSelector('::2'))                          // [1, 3, 5, 7, 9]\n    -\u003esubview(new MaskSelector([true, false, true, true, true])) // [1, 5, 7, 9]\n    -\u003esubview(new IndexListSelector([0, 1, 2]))                  // [1, 5, 7]\n    -\u003esubview(new SliceSelector('1:'));                          // [5, 7]\n\n$subview[':'] = [55, 77];\nprint_r($originalArray); // [1, 2, 3, 4, 55, 6, 77, 8, 9, 10]\n\n// Fluent scripting style\n$originalArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n$subview = ArrayView::toView($originalArray)\n    -\u003esubview('::2')                           // [1, 3, 5, 7, 9]\n    -\u003esubview([true, false, true, true, true]) // [1, 5, 7, 9]\n    -\u003esubview([0, 1, 2])                       // [1, 5, 7]\n    -\u003esubview('1:');                           // [5, 7]\n\n$subview[':'] = [55, 77];\nprint_r($originalArray); // [1, 2, 3, 4, 55, 6, 77, 8, 9, 10]\n```\n\n### Selectors Pipe\n\nCreate pipelines of selections that can be saved and applied again and again to new array views.\n```php\nuse Smoren\\ArrayView\\Selectors\\IndexListSelector;\nuse Smoren\\ArrayView\\Selectors\\MaskSelector;\nuse Smoren\\ArrayView\\Selectors\\SliceSelector;\nuse Smoren\\ArrayView\\Views\\ArrayView;\n\n$originalArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n$selector = new PipeSelector([\n    new SliceSelector('::2'),\n    new MaskSelector([true, false, true, true, true]),\n    new IndexListSelector([0, 1, 2]),\n    new SliceSelector('1:'),\n]);\n\n$view = ArrayView::toView($originalArray);\n$subview = $view-\u003esubview($selector);\nprint_r($subview[':']); // [5, 7]\n\n$subview[':'] = [55, 77];\nprint_r($originalArray); // [1, 2, 3, 4, 55, 6, 77, 8, 9, 10]\n```\n\n## Documentation\nFor detailed documentation and usage examples, please refer to the\n[API documentation](https://smoren.github.io/array-view-php/packages/Application.html).\n\n## Unit testing\n```\ncomposer install\ncomposer test-init\ncomposer test\n```\n\n## Contributing\nContributions are welcome! Feel free to open an issue or submit a pull request on the [GitHub repository](https://github.com/Smoren/array-view-php).\n\n## Standards\nArrayView conforms to the following standards:\n\n* PSR-1 — [Basic coding standard](https://www.php-fig.org/psr/psr-1/)\n* PSR-4 — [Autoloader](https://www.php-fig.org/psr/psr-4/)\n* PSR-12 — [Extended coding style guide](https://www.php-fig.org/psr/psr-12/)\n\n## License\nArrayView PHP is licensed under the MIT License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmoren%2Farray-view-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmoren%2Farray-view-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmoren%2Farray-view-php/lists"}