{"id":14987417,"url":"https://github.com/tfhinc/ci-ray","last_synced_at":"2026-01-18T11:42:04.705Z","repository":{"id":57067428,"uuid":"159423252","full_name":"TFHInc/ci-ray","owner":"TFHInc","description":"Ray is an expressive PHP array library for the Codeigniter framework","archived":false,"fork":false,"pushed_at":"2018-12-04T03:46:44.000Z","size":13,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-11T13:21:23.513Z","etag":null,"topics":["array","codeigniter","codeigniter-library","ray"],"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/TFHInc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-28T01:14:22.000Z","updated_at":"2022-11-26T18:02:24.000Z","dependencies_parsed_at":"2022-08-24T10:20:11.638Z","dependency_job_id":null,"html_url":"https://github.com/TFHInc/ci-ray","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TFHInc%2Fci-ray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TFHInc%2Fci-ray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TFHInc%2Fci-ray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TFHInc%2Fci-ray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TFHInc","download_url":"https://codeload.github.com/TFHInc/ci-ray/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247363146,"owners_count":20926893,"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","codeigniter","codeigniter-library","ray"],"created_at":"2024-09-24T14:14:35.113Z","updated_at":"2026-01-18T11:42:04.659Z","avatar_url":"https://github.com/TFHInc.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ray\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![PHP Version][ico-php-version]][link-packagist]\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![Total Downloads][ico-downloads]][link-downloads]\n\nRay is an expressive PHP array library for the [Codeigniter](https://codeigniter.com/) framework.\n\n## Requirements\n\n- PHP \u003e= 7.1.0\n- CodeIgnitor 3.x\n\n## Installation\n\n```bash\ncomposer require tfhinc/ci-ray\n```\n\nRun the post install command to publish the helper and class files to the appropriate CI directories:\n```bash\ncomposer --working-dir=vendor/tfhinc/ci-ray/ run-script publish-files\n```\n\n## Loading the Library\n\nThere are a few available options for loading the Warehouse library:\n\n### Using the `ray()` helper function\n\nThe Ray helper function will resolve the `Ray` class via the CI instance. It will either load the class or return the existing class instance:\n\n``` php\n$this-\u003eload-\u003ehelper('ray');\n```\n\n### Using the Ray Class\n\nThe Ray class can be instantiated when you require it:\n\n``` php\n$ray = new TFHInc/Ray/Ray();\n```\n\n### Using the Ray CI Library\n\nThe Ray class can be loaded like any other CI library:\n\n``` php\n$this-\u003eload-\u003elibrary('Ray');\n```\n\n## Usage\n\n`Ray` can be used in a variety of ways to manipulate and transfrom arrays.\n\n### Method Usage\n\n`Ray` enables you to interact with arrays using simple methods that return a single value or a transformed array:\n\n```php\n// Given an array...\n\n$fruit = [\n    'lemon' =\u003e 'yellow',\n    'apple' =\u003e 'red',\n    'lime' =\u003e 'green',\n    'pear' =\u003e 'green',\n];\n\n// ...Get all of the keys except 'apple' and 'lime':\n\nray($fruit)-\u003eexcept(['apple', 'lime'])-\u003etoArray();\n\n/*\n\n    [\n        'lemon' =\u003e 'yellow',\n        'pear' =\u003e 'green',\n    ]\n\n\n*/\n\n// ...Get the first value:\n\nray($fruit)-\u003efirst();\n\n/*\n\n    'yellow'\n\n*/\n\n// ...Sort by value:\n\nray($fruit)-\u003esortByValues()-\u003etoArray();\n\n/*\n\n    [\n        'lime' =\u003e 'green',\n        'pear' =\u003e 'green',\n        'apple' =\u003e 'red',\n        'lemon' =\u003e 'yellow',\n    ]\n\n*/\n```\n\n### Method Chaining\n\nThe power of `Ray` is displayed when chaining methods together to manipulate an array:\n\n``` php\n// Given a multidimensional array...\n\n$fruit_multi = [\n    [ 'id' =\u003e 1, 'name' =\u003e 'lemon', 'color' =\u003e 'yellow',    'price' =\u003e 2.25, 'qty' =\u003e 2 ],\n    [ 'id' =\u003e 2, 'name' =\u003e 'apple', 'color' =\u003e 'red',       'price' =\u003e 0.99, 'qty' =\u003e 12 ],\n    [ 'id' =\u003e 3, 'name' =\u003e 'lime',  'color' =\u003e 'green',     'price' =\u003e 3.50, 'qty' =\u003e 9 ],\n    [ 'id' =\u003e 4, 'name' =\u003e 'pear',  'color' =\u003e 'green',     'price' =\u003e 2.00, 'qty' =\u003e 7 ],\n];\n\n// ...Group the array by the 'color' key and only return keys 'red' or 'green':\n\nray($fruit_multi)-\u003egroupBy('color')-\u003eonly(['red', 'green'])-\u003etoArray();\n\n/*\n    [\n        'red' =\u003e [\n            [\n                'id' =\u003e 2,\n                'name' =\u003e 'apple',\n                'color' =\u003e 'red',\n                'price' =\u003e 0.99,\n                'qty' =\u003e 12,\n            ],\n        ],\n        'green' =\u003e [\n            [\n                'id' =\u003e 3,\n                'name' =\u003e 'lime',\n                'color' =\u003e 'green',\n                'price' =\u003e 3.5,\n                'qty' =\u003e 9,\n            ],\n            [\n                'id' =\u003e 4,\n                'name' =\u003e 'pear',\n                'color' =\u003e 'green',\n                'price' =\u003e 2,\n                'qty' =\u003e 7,\n            ],\n        ],\n    ]\n*/\n\n// ...Where the 'color' key is 'green', sum the 'price':\n\nray($fruit_multi)-\u003ewhere('color', 'green')-\u003esum('price');\n\n/*\n\n    5.5\n\n*/\n\n// ...Where the 'color' key is not 'green', filter the items that have a 'price' greater than 2:\n\nray($fruit_multi)-\u003ewhereNot('color', 'green')-\u003efilter(function($item, $key) {\n    return $item['price'] \u003e 2;\n})-\u003etoArray();\n\n/*\n\n    [\n        [\n            'id' =\u003e 1,\n            'name' =\u003e 'lemon',\n            'color' =\u003e 'yellow',\n            'price' =\u003e 2.25,\n            'qty' =\u003e 2,\n        ]\n    ]\n\n*/\n\n// ...Where the 'color' key is 'green' or 'yellow', count the number of items:\n\nray($fruit_multi)-\u003ewhereIn('color', ['green','yellow'])-\u003ecount();\n\n/*\n\n    3\n\n*/\n\n// ...Retreive a column by the 'color' key and key the transformed array by the `name` key, sort by key:\n\nray($fruit_multi)-\u003ecolumn('color', 'name')-\u003esortByKeys()-\u003etoArray();\n\n/*\n\n    [\n        'apple' =\u003e 'red',\n        'lemon' =\u003e 'yellow',\n        'lime' =\u003e 'green',\n        'pear' =\u003e 'green',\n    ]\n\n*/\n```\n\n### Method Return Types\n\n`Ray` methods will return different data types depedent on the desired outcome of the method. Each documented method definition indicates the data type returned.\n\n- The `toArray()` method should be called at the end of the method chaining sequence to return the final transformed `array`:\n\n```php\n// toArray() returns the final transformed array:\n\nray($fruit_multi)-\u003ecolumn('color', 'name')-\u003esortByKeys()-\u003etoArray();\n\n/*\n\n    [\n        'apple' =\u003e 'red',\n        'lemon' =\u003e 'yellow',\n        'lime' =\u003e 'green',\n        'pear' =\u003e 'green',\n    ]\n\n*/\n```\n\n- Methods that return a `string` or an `integer` do not require the `toArray()` method. These methods should be called at the end of the method chaining sequence:\n\n```php\n// count() returns an integer:\n\nray($fruit_multi)-\u003ewhereIn('color', ['green','yellow'])-\u003ecount();\n\n/*\n\n    3\n\n*/\n\n// first() returns a string:\n\nray($fruit)-\u003efirst();\n\n/*\n\n    'yellow'\n\n*/\n```\n\n## Available Methods\n\nThe following methods are currently available:\n\n- [sortByKeys](#sortbykeys)\n- [sortByValues](#sortbyvalues)\n- [has](#hasstring-key)\n- [contains](#containsmixed-value--mixed-key)\n- [sum](#sumstring-key)\n- [avg](#avgstring-key)\n- [count](#count)\n- [values](#values)\n- [first](#first)\n- [last](#last)\n- [except](#exceptarray-keys)\n- [only](#onlyarray-keys)\n- [unique](#uniquestring-key)\n- [groupBy](#groupbystring-key)\n- [column](#columnstring-key-string-key_by)\n- [where](#wherestring-key-string-value)\n- [whereIn](#whereinstring-key-array-values)\n- [whereNot](#wherenotstring-key-string-value)\n- [whereNotIn](#wherenotinstring-key-array-values)\n- [filter](#filtercallable-callback)\n- [reduce](#reducecallable-callback)\n\n#### `sortByKeys()`\nSort the array by its keys.\n\n```php\nray($fruit)-\u003esortByKeys()-\u003etoArray();\n\n/*\n\n    Array\n    (\n        [apple] =\u003e red\n        [lemon] =\u003e yellow\n        [lime] =\u003e green\n        [pear] =\u003e green\n    )\n\n*/\n```\n\n#### `sortByValues()`\nSort the array by its values.\n\n```php\nray($fruit)-\u003esortByValues()-\u003etoArray();\n\n/*\n\n    Array\n    (\n        [lime] =\u003e green\n        [apple] =\u003e red\n        [lemon] =\u003e yellow\n    )\n\n*/\n```\n\n#### `has(string $key)`\nDetermine if the array contains a given key.\n\n```php\nray($fruit_multi)-\u003ehas('price');\n\n// true\n\nray($fruit_multi)-\u003ehas('brand');\n\n// false\n```\n\n#### `contains(string $value [, string $key])`\nDetermine if the array contains a given value.\n\n```php\nray($fruit_multi)-\u003econtains('green');\n\n// true\n\nray($fruit_multi)-\u003econtains('brown');\n\n// false\n```\n\nOptionally provide a key to limit the `contains()` check\n\n```php\nray($fruit_multi)-\u003econtains('color', 'green');\n\n// true\n\nray($fruit_multi)-\u003econtains('color', 'brown');\n\n// false\n```\n\n#### `sum(string $key)`\nGet the sum of the values for the provided key.\n\n```php\nray($fruit_multi)-\u003esum('qty');\n\n// 30\n\nray($fruit_multi)-\u003esum('price');\n\n// 8.74\n```\n\n#### `avg(string $key)`\nGet the average of the values for the provided key.\n\n```php\nray($fruit_multi)-\u003eavg('price');\n\n// 2.185\n```\n\n#### `count()`\nGet the count of the values.\n\n```php\nray($fruit_multi)-\u003ecount();\n\n// 4\n```\n\n#### `values()`\nGet the values of the array. Can be used to reindex the array with consecutive integers.\n\n```php\nray($fruit)-\u003evalues()-\u003etoArray();\n\n/*\n\n    Array\n    (\n        [0] =\u003e yellow\n        [1] =\u003e red\n        [2] =\u003e green\n        [3] =\u003e green\n    )\n\n*/\n```\n\n#### `first()`\nGet the first value of the array.\n\n```php\nray($fruit)-\u003efirst();\n\n// yellow\n\nray($fruit_multi)-\u003efirst();\n\n/*\n\n    Array\n    (\n        [id] =\u003e 1\n        [name] =\u003e lemon\n        [color] =\u003e yellow\n        [price] =\u003e 2.25\n        [qty] =\u003e 2\n    )\n\n*/\n```\n\n#### `last()`\nGet the last value of the array.\n\n```php\nray($fruit)-\u003elast();\n\n// green\n\nray($fruit_multi)-\u003elast();\n\n/*\n\n    Array\n    (\n        [id] =\u003e 4\n        [name] =\u003e pear\n        [color] =\u003e green\n        [price] =\u003e 2\n        [qty] =\u003e 7\n    )\n\n*/\n```\n\n#### `except(array $keys)`\nGet all array elements except for the provided keys.\n\n```php\nray($fruit)-\u003eexcept(['apple', 'lime'])-\u003etoArray();\n\n/*\n\n    Array\n    (\n        [lemon] =\u003e yellow\n        [pear] =\u003e green\n    )\n\n*/\n```\n\n#### `only(array $keys)`\nOnly get the array elements for the provided keys.\n\n```php\nray($fruit)-\u003eonly(['apple', 'lime'])-\u003etoArray();\n\n/*\n\n    Array\n    (\n        [apple] =\u003e red\n        [lime] =\u003e green\n    )\n\n*/\n```\n\n#### `unique([string $key])`\nLimit the array by unique value. Optionally limit by unique values of the provided key. The array keys are preserved. If there are duplicate values, the first key/value pair will be retained.\n\n```php\nray($fruit)-\u003eunique()-\u003etoArray();\n\n/*\n\n    Array\n    (\n        [lemon] =\u003e yellow\n        [apple] =\u003e red\n        [lime] =\u003e green\n    )\n\n*/\n\nray($fruit_multi)-\u003eunique('color')-\u003etoArray();\n\n/*\n\n    Array\n    (\n        [0] =\u003e Array\n            (\n                [id] =\u003e 1\n                [name] =\u003e lemon\n                [color] =\u003e yellow\n                [price] =\u003e 2.25\n                [qty] =\u003e 2\n            )\n    \n        [1] =\u003e Array\n            (\n                [id] =\u003e 2\n                [name] =\u003e apple\n                [color] =\u003e red\n                [price] =\u003e 0.99\n                [qty] =\u003e 12\n            )\n    \n        [2] =\u003e Array\n            (\n                [id] =\u003e 3\n                [name] =\u003e lime\n                [color] =\u003e green\n                [price] =\u003e 3.5\n                [qty] =\u003e 9\n            )\n    \n    )\n\n*/\n```\n\n#### `groupBy(string $key)`\nGroup the array by a given key.\n\n```php\nray($fruit_multi)-\u003egroupBy('color')-\u003etoArray();\n\n/*\n\n    Array\n    (\n        [yellow] =\u003e Array\n            (\n                [0] =\u003e Array\n                    (\n                        [id] =\u003e 1\n                        [name] =\u003e lemon\n                        [color] =\u003e yellow\n                        [price] =\u003e 2.25\n                        [qty] =\u003e 2\n                    )\n    \n            )\n    \n        [red] =\u003e Array\n            (\n                [0] =\u003e Array\n                    (\n                        [id] =\u003e 2\n                        [name] =\u003e apple\n                        [color] =\u003e red\n                        [price] =\u003e 0.99\n                        [qty] =\u003e 12\n                    )\n    \n            )\n    \n        [green] =\u003e Array\n            (\n                [0] =\u003e Array\n                    (\n                        [id] =\u003e 3\n                        [name] =\u003e lime\n                        [color] =\u003e green\n                        [price] =\u003e 3.5\n                        [qty] =\u003e 9\n                    )\n    \n                [1] =\u003e Array\n                    (\n                        [id] =\u003e 4\n                        [name] =\u003e pear\n                        [color] =\u003e green\n                        [price] =\u003e 2\n                        [qty] =\u003e 7\n                    )\n    \n            )\n    \n    )\n\n*/\n```\n\n#### `column(string $key, [string $key_by])`\nRetreive an entire column from the array. Optionally key the new transformed array by the provided key_by argument.\n\n```php\nray($fruit_multi)-\u003ecolumn('color')-\u003etoArray();\n\n/*\n\n    Array\n    (\n        [0] =\u003e yellow\n        [1] =\u003e red\n        [2] =\u003e green\n        [3] =\u003e green\n    )\n\n*/\n\nray($fruit_multi)-\u003ecolumn('color', 'name')-\u003etoArray();\n\n/*\n\n    Array\n    (\n        [lemon] =\u003e yellow\n        [apple] =\u003e red\n        [lime] =\u003e green\n        [pear] =\u003e green\n    )\n\n*/\n```\n\n#### `where(string $key, string $value)`\nLimit the array by a specific key and value.\n\n```php\nray($fruit_multi)-\u003ewhere('color', 'green')-\u003etoArray();\n\n/*\n\n    Array\n    (\n        [2] =\u003e Array\n            (\n                [id] =\u003e 3\n                [name] =\u003e lime\n                [color] =\u003e green\n                [price] =\u003e 3.5\n                [qty] =\u003e 9\n            )\n    \n        [3] =\u003e Array\n            (\n                [id] =\u003e 4\n                [name] =\u003e pear\n                [color] =\u003e green\n                [price] =\u003e 2\n                [qty] =\u003e 7\n            )\n    \n    )\n\n*/\n```\n\n#### `whereIn(string $key, array $values)`\nLimit the array by a specific key and an array of values.\n\n```php\nray($fruit_multi)-\u003ewhereIn('color', ['green', 'yellow'])-\u003etoArray();\n\n/*\n\n    Array\n    (\n        [0] =\u003e Array\n            (\n                [id] =\u003e 1\n                [name] =\u003e lemon\n                [color] =\u003e yellow\n                [price] =\u003e 2.25\n                [qty] =\u003e 2\n            )\n    \n        [2] =\u003e Array\n            (\n                [id] =\u003e 3\n                [name] =\u003e lime\n                [color] =\u003e green\n                [price] =\u003e 3.5\n                [qty] =\u003e 9\n            )\n    \n        [3] =\u003e Array\n            (\n                [id] =\u003e 4\n                [name] =\u003e pear\n                [color] =\u003e green\n                [price] =\u003e 2\n                [qty] =\u003e 7\n            )\n    \n    )\n\n*/\n```\n\n#### `whereNot(string $key, string $value)`\nLimit the array by a given key and value.\n\n```php\nray($fruit_multi)-\u003ewhereNot('color', 'green')-\u003etoArray();\n\n/*\n\n    Array\n    (\n        [0] =\u003e Array\n            (\n                [id] =\u003e 1\n                [name] =\u003e lemon\n                [color] =\u003e yellow\n                [price] =\u003e 2.25\n                [qty] =\u003e 2\n            )\n    \n        [1] =\u003e Array\n            (\n                [id] =\u003e 2\n                [name] =\u003e apple\n                [color] =\u003e red\n                [price] =\u003e 0.99\n                [qty] =\u003e 12\n            )\n    \n    )\n\n*/\n```\n\n#### `whereNotIn(string $key, array $values)`\nLimit the array by a specific key and an array of values.\n\n```php\nray($fruit)-\u003ewhereNotIn('color', ['green', 'yellow'])-\u003etoArray();\n\n/*\n\n    Array\n    (\n        [1] =\u003e Array\n            (\n                [id] =\u003e 2\n                [name] =\u003e apple\n                [color] =\u003e red\n                [price] =\u003e 0.99\n                [qty] =\u003e 12\n            )\n    \n    )\n\n*/\n```\n\n#### `filter(callable $callback)`\nFilter the array by the provided callback.\n\n```php\nray($fruit_multi)-\u003efilter(function($value, $key) {\n    return $value['price'] \u003e 3;\n})-\u003etoArray();\n\n/*\n\n    Array\n    (\n        [2] =\u003e Array\n            (\n                [id] =\u003e 3\n                [name] =\u003e lime\n                [color] =\u003e green\n                [price] =\u003e 3.5\n                [qty] =\u003e 9\n            )\n    \n)\n\n*/\n\nray($fruit_multi)-\u003efilter(function($value, $key) {\n    return $value['price'] \u003c 3;\n})-\u003etoArray();\n\n/*\n\n    Array\n    (\n        [0] =\u003e Array\n            (\n                [id] =\u003e 1\n                [name] =\u003e lemon\n                [color] =\u003e yellow\n                [price] =\u003e 2.25\n                [qty] =\u003e 2\n            )\n    \n        [1] =\u003e Array\n            (\n                [id] =\u003e 2\n                [name] =\u003e apple\n                [color] =\u003e red\n                [price] =\u003e 0.99\n                [qty] =\u003e 12\n            )\n    \n        [3] =\u003e Array\n            (\n                [id] =\u003e 4\n                [name] =\u003e pear\n                [color] =\u003e green\n                [price] =\u003e 2\n                [qty] =\u003e 7\n            )\n    \n    )\n\n*/\n```\n\n#### `reduce(callable $callback)`\nReduce the array by a callback to a single value.\n\n```php\nray($fruit_multi)-\u003ereduce(function($carry, $value) {\n    return $value['qty'] \u003c 3 ? $carry + $value['qty'] : $carry;\n});\n\n// 2\n```\n\n## Contributing\n\nFeel free to create a GitHub issue or send a pull request with any bug fixes. Please see the GutHub issue tracker for isses that require help.\n\n## Acknowledgements\n\n- [Colin Rafuse][link-author]\n- [All Contributors][link-contributors]\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/tfhinc/ci-ray.svg?style=flat-square\n[ico-php-version]: https://img.shields.io/packagist/php-v/tfhinc/ci-ray.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/tfhinc/ci-ray.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/tfhinc/ci-ray\n[link-downloads]: https://packagist.org/packages/tfhinc/ci-ray\n[link-author]: https://github.com/crafuse\n[link-contributors]: ../../contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftfhinc%2Fci-ray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftfhinc%2Fci-ray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftfhinc%2Fci-ray/lists"}