php - 借助“帮助”功能创建键 => 值数组
问题描述
我有一个具有以下值的二维数组:
[
'id' => 12,
'title' => 'the title', //and a few other key => value
],
[
'id' => 13,
'title' => 'the title 13', // and a few other key => value
],...
最后,我需要一个只有id 和 title的多维数组
[ $item['id'] => $item['title'], ...]
通常,我正在做一个简单的 foreach 来实现这一点,但我现在想使用 php 函数。我已经这样做了,但是有没有合适的方法来做到这一点?
$list = array_combine(array_column($list_forms, 'id'), array_column($list_forms, 'title'));
解决方案
推荐阅读
- ios - 找到正确的方法来增加用户脚上的鞋子
- php - 在 Laravel 的命名空间之前添加 Facades,它是如何工作的?
- linux - 无法在 Linux(Ubuntu)上使用 glew.h
- graphql - GraphQL - 联合类型给出错误 no class could be found for that type name
- reactjs - Production Cookie 出现在 Development and Staging 中
- c# - 创建包含 .cshtml 文件的 Visual Studio 自定义模板并打包到 Nuget 包中
- c++ - 在 VSCode 中编写的库要求是什么以及如何通过 browse.path 和设置“同步”我的目录
- typescript - Highstock / Angular-cli : TypeError: this.getChartData is not a function at I.afterSetExtreme
- javascript - PHP 标记内的内联 JavaScript 函数
- javascript - 如何用锚点击上的另一个部分替换页面上的一个部分?