{"id":18604284,"url":"https://github.com/izica/phalcon-collection","last_synced_at":"2026-04-25T23:36:39.034Z","repository":{"id":139291621,"uuid":"91947523","full_name":"izica/phalcon-collection","owner":"izica","description":"PhalconPHP library for work with arrays and collections","archived":false,"fork":false,"pushed_at":"2017-05-26T09:35:07.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-16T18:44:20.394Z","etag":null,"topics":["array","collection","composer","library","phalcon","phalcon-collection","phalconphp","phalconphp-collection","php","php-collection","php7"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/izica.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2017-05-21T09:56:52.000Z","updated_at":"2022-02-12T14:12:57.000Z","dependencies_parsed_at":"2024-07-08T18:00:22.558Z","dependency_job_id":null,"html_url":"https://github.com/izica/phalcon-collection","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/izica/phalcon-collection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izica%2Fphalcon-collection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izica%2Fphalcon-collection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izica%2Fphalcon-collection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izica%2Fphalcon-collection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izica","download_url":"https://codeload.github.com/izica/phalcon-collection/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izica%2Fphalcon-collection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32280979,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T18:29:39.964Z","status":"ssl_error","status_checked_at":"2026-04-25T18:29:32.149Z","response_time":59,"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":["array","collection","composer","library","phalcon","phalcon-collection","phalconphp","phalconphp-collection","php","php-collection","php7"],"created_at":"2024-11-07T02:17:16.812Z","updated_at":"2026-04-25T23:36:39.018Z","avatar_url":"https://github.com/izica.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Todo List\n- [x] work with MVC collection\n- [ ] all\n- [x] [average](#average)\n- [x] [chunk](#chunk)\n- [x] [groupBy](#groupby)\n- [x] [keyBy](#keyby)\n- [x] [has](#has)\n- [ ] last\n- [ ] map\n- [ ] unique\n- [x] [toArray](#toarray)\n- [x] [toJson](#tojson)\n- [ ] where\n- [ ] zip\n- [ ] etc....\n\n## Register service:\n```php\n    $di = new DI();\n    $di-\u003eset('collection', function() {\n        return new IzicaCollection();\n    });\n```\n## Usage:\n```php\n    use Phalcon\\Mvc\\Controller;\n\n    class IndexController extends Controller\n    {\n        public function indexAction()\n        {\n            $arCars = Cars::find();\n            $jsonResponse = $this-\u003ecollection-\u003ecreate($arCars)-\u003egroupBy('year')-\u003etoJson();\n        }\n    }\n```\n\n# Functions\n#### average\n```php\n    $arr = [\n        ['value' =\u003e 2, 'value2' =\u003e 4, 'value3' =\u003e 'foo'],\n        ['value' =\u003e 6, 'value2' =\u003e 1, 'value3' =\u003e 'bar']\n    ];\n    $arResult = $this-\u003ecollection-\u003ecreate($arr)-\u003eaverage();\n    //Array\n    //(\n    //    [value] =\u003e 4\n    //    [value2] =\u003e 2.5\n    //)\n    $arResult = $this-\u003ecollection-\u003ecreate($arr)-\u003eaverage('value');\n    //4\n    $collection = $this-\u003ecollection-\u003ecreate($arr)-\u003eaverage(['value']);\n    //Array\n    //(\n    //    [value] =\u003e 4\n    //)\n    $collection = $this-\u003ecollection-\u003ecreate([1, 5, 6 ,7])-\u003eaverage();\n    //4.75\n```\n#### chunk\n```php\n    $collection = $this-\u003ecollection-\u003ecreate([1, 2, 3, 4, 5])-\u003echunk(2);\n    //[\n    //    [1, 2], \n    //    [3, 4]\n    //    [5]\n    //]\n```\n#### groupBy\n```php\n    $arResult = $this-\u003ecollection-\u003ecreate($arr)-\u003egroupBy('value');\n    $arResult = $this-\u003ecollection-\u003ecreate($arr)-\u003egroupBy(function($arItem){\n        return (int)$arItem['value'] * 2;\n    });\n```\n#### keyBy\n```php\n    $arResult = $this-\u003ecollection-\u003ecreate($arr)-\u003ekeyBy('id');\n    $arResult = $this-\u003ecollection-\u003ecreate($arr)-\u003ekeyBy(function($arItem){\n        return strtoupper($arItem['code']);\n    });\n```\n#### has\n```php\n    //has(key, value);\n    $arr = ['value' =\u003e 'bar', 'value2' =\u003e 'foo'];\n    $result = $this-\u003ecollection-\u003ecreate($arr)-\u003ehas('value'); // true\n    $result = $this-\u003ecollection-\u003ecreate($arr)-\u003ehas('value', 'bar'); // true\n    $result = $this-\u003ecollection-\u003ecreate($arr)-\u003ehas('value', 'xyz'); // false\n\n```\n#### toArray\ntransforms activeRecord to Array\n```php\n    $arResult = $this-\u003ecollection-\u003ecreate(Cars::find())-\u003etoArray()-\u003egroupBy('value'); // return result in Array Object after groupBy\n    $arResult = $this-\u003ecollection-\u003ecreate(Cars::find())-\u003etoArray(true) // return result in Array string instant, ~Cars::find()-\u003etoArray();\n```\n#### toJson\n```php\n    $arResult = $this-\u003ecollection-\u003ecreate($arr)-\u003etoJson()-\u003egroupBy('value'); // return result in JSON string after groupBy\n    $arResult = $this-\u003ecollection-\u003ecreate($arr)-\u003etoJson(true) // return result in JSON string instant\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizica%2Fphalcon-collection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizica%2Fphalcon-collection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizica%2Fphalcon-collection/lists"}