{"id":20485347,"url":"https://github.com/houdunwang/arr","last_synced_at":"2025-08-22T05:32:05.008Z","repository":{"id":48291647,"uuid":"76472167","full_name":"houdunwang/arr","owner":"houdunwang","description":"数组增强组件主要是对数组等数据进行处理，如无限级分类操作、商品规格的迪卡尔乘积运算等。","archived":false,"fork":false,"pushed_at":"2021-08-03T02:45:02.000Z","size":29,"stargazers_count":65,"open_issues_count":2,"forks_count":16,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-30T01:39:39.433Z","etag":null,"topics":["array","category","laravel","php"],"latest_commit_sha":null,"homepage":null,"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/houdunwang.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}},"created_at":"2016-12-14T15:30:15.000Z","updated_at":"2023-02-24T03:14:24.000Z","dependencies_parsed_at":"2022-09-15T02:01:16.409Z","dependency_job_id":null,"html_url":"https://github.com/houdunwang/arr","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/houdunwang/arr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houdunwang%2Farr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houdunwang%2Farr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houdunwang%2Farr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houdunwang%2Farr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/houdunwang","download_url":"https://codeload.github.com/houdunwang/arr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houdunwang%2Farr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271590278,"owners_count":24786187,"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","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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","category","laravel","php"],"created_at":"2024-11-15T16:29:37.788Z","updated_at":"2025-08-22T05:32:04.666Z","avatar_url":"https://github.com/houdunwang.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 数组增强\n\n数组增强组件主要是对数组等数据进行处理，如无限级分类操作、商品规格的迪卡尔乘积运算等。\n\n### 安装组件\n使用 composer 命令进行安装或下载源代码使用。\n\n```\ncomposer require houdunwang/arr\n```\n\u003e HDPHP 框架已经内置此组件，无需要安装\n\n## 功能介绍\n#### 根据键名获取数据\n如果键名不存在时返回默认值，支持键名的点语法\n\n```\n$d=['a'=\u003e1,'b'=\u003e2];\n(new \\houdunwang\\arr\\Arr())-\u003eget($d,'c','没有数据哟');\n```\n使用点语法查找：\n```\n$d = ['web' =\u003e [ 'id' =\u003e 1, 'url' =\u003e 'houdunwang.com' ]];\n(new \\houdunwang\\arr\\Arr())-\u003eget($d,'web.url');\n```\n\n#### 排队字段获取数据\n以下代码获取除 id、url以外的数据\n\n```\n$d = ['id' =\u003e 1,'url' =\u003e 'houdunwang.com','name'=\u003e'后盾人'];\nprint_r((new \\houdunwang\\arr\\Arr())-\u003egetExtName($d,['id','url']));\n```\n\n#### 设置数组元素值支持点语法\n\n```\n$data = (new \\houdunwang\\arr\\Arr())-\u003eset([],'a.b.c',99);\n```\n\n#### 改变数组键名大小写\n\n```\n$data = array('name'=\u003e'houdunwang',array('url'=\u003e'hdphp.com'));\n$data = (new \\houdunwang\\arr\\Arr())-\u003ekeyCase($data,1); \n第2个参数为类型： 1 大写  0 小写\n```\n\n#### 不区分大小写检测键名是否存\n\n```\n(new \\houdunwang\\arr\\Arr())-\u003ekeyExists('Hd',['hd'=\u003e'后盾网']);\n```\n\n#### 数组值大小写转换\n\n```\n(new \\houdunwang\\arr\\Arr())-\u003evalueCase(['name'=\u003e'houdunwang'],1); \n第2个参数为类型： 1 大写  0 小写\n```\n\n#### 数组进行整数映射转换\n\n```\n$data = ['status'=\u003e1];\n$d = (new \\houdunwang\\arr\\Arr())-\u003eintToString($data,['status'=\u003e[0=\u003e'关闭',1=\u003e'开启']]); \n```\n\n#### 数组中的字符串数字转为数值类型\n\n```\n$data = ['status'=\u003e'1','click'=\u003e'200'];\n$d = (new \\houdunwang\\arr\\Arr())-\u003estringToInt($data); \n```\n\n#### 根据下标过滤数据元素\n\n```\n$d = [ 'id' =\u003e 1, 'url' =\u003e 'houdunwang.com','title'=\u003e'后盾网' ];\nprint_r((new \\houdunwang\\arr\\Arr())-\u003efilterKeys($d,['id','url']));\n//过滤 下标为 id 的元素\n```\n\n当第三个参数为 0 时只保留指定的元素\n```\n$d = [ 'id' =\u003e 1, 'url' =\u003e 'houdunwang.com','title'=\u003e'后盾网' ];\nprint_r((new \\houdunwang\\arr\\Arr())-\u003efilterKeys($d,['id'],0));\n//只显示id与title 的元素\n```\n\n#### 获得树状结构\n\n```\n(new \\houdunwang\\arr\\Arr())-\u003etree($data, $title, $fieldPri = 'cid', $fieldPid = 'pid');\n参数                   \t说明\n$data                 \t数组\n$title                \t字段名称\n$fieldPri             \t主键 id\n$fieldPid             \t父 id\n```\n\n#### 获得目录列表\n\n```\n(new \\houdunwang\\arr\\Arr())-\u003echannelList($data, $pid = 0, $html = \"\u0026nbsp;\", $fieldPri = 'cid', $fieldPid = 'pid', $level = 1);\n参数                      \t说明 \ndata                 \t操作的数组\npid                  \t父级栏目的 id 值\nhtml                \t栏目名称前缀，用于在视图中显示层次感的栏目列表 \nfieldPri              \t唯一键名，如果是表则是表的主键\nfieldPid              \t父 ID 键名\nlevel                 \t等级（不需要传参数，系统运行时使用 ) \n```\n\n#### 获得多级目录列表（多维数组）\n\n```\n(new \\houdunwang\\arr\\Arr())-\u003echannelLevel($data, $pid = 0, $html = \"\u0026nbsp;\", $fieldPri = 'cid', $fieldPid = 'pid') \n参数                          \t说明\ndata                      \t操作的数组\npid                      \t父级栏目的 id 值\nhtml                     \t栏目名称前缀，用于在视图中显示层次感的栏目列表\nfieldPri                 \t唯一键名，如果是表则是表的主键\nfieldPid                  \t父 ID 键名\n```\n\n#### 获得所有父级栏目\n\n```\n(new \\houdunwang\\arr\\Arr())-\u003eparentChannel($data, $sid, $fieldPri = 'cid', $fieldPid = 'pid');\n参数                          \t说明\ndata                      \t操作的数组\nsid                      \t子栏目\nfieldPri                 \t唯一键名，如果是表则是表的主键\nfieldPid                  \t父 ID 键名\n\n```\n\n#### 是否为子栏目\n\n```\n(new \\houdunwang\\arr\\Arr())-\u003eisChild($data, $sid, $pid, $fieldPri = 'cid', $fieldPid = 'pid')\n参数                          \t说明\ndata                      \t操作的数组\nsid                      \t子栏目id\npid                      \t父栏目id\nfieldPri                 \t唯一键名，如果是表则是表的主键\nfieldPid                  \t父 ID 键名\n```\n\n#### 是否有子栏目\n\n```\n(new \\houdunwang\\arr\\Arr())-\u003ehasChild($data, $cid, $fieldPid = 'pid')\n参数                          \t说明\ndata                      \t操作的数组\ncid                      \t栏目cid\nfieldPid                  \t父 ID 键名\n```\n\n#### 无限级栏目分类\n\n```\n(new \\houdunwang\\arr\\Arr())-\u003ecategory($categories,$pid = 0,$title = 'title',$id = 'id',$parent_id = 'parent_id')\n参数\t\t\t\t\t\t\t\t说明\n$categories\t\t\t\t\t\t操作的数组\n$pid\t\t\t\t\t\t\t\t父级编号\n$title                  \t\t栏目字段\n$id\t\t\t\t\t\t\t\t主键名\n$parent_id\t\t\t\t\t\t父级字段名\n```\n\n#### 迪卡尔乘积\n\n```\n(new \\houdunwang\\arr\\Arr())-\u003edescarte($arr, $tmp = array())\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoudunwang%2Farr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoudunwang%2Farr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoudunwang%2Farr/lists"}