php - 如何在 Laravel 中按键获取多维数组的值?
问题描述
例如,假设您有一个包含多个键(和值)的常量多维数组,但您想用它的值过滤掉特定的键。请参阅下面的示例数组:
const defaultInvestmentFields = [
[
'type' => 'system',
'investment_name' => 'Ballast'
],
[
'type' => 'system',
'investment_name' => 'Inverters'
],
[
'type' => 'system',
'investment_name' => 'Extra garantie inverters'
]
];
我想要的输出是一个只有投资名称值的数组。喜欢['Ballast', 'Inverters', 'Extra garantie inverters']
。
解决方案
除了@Levi 's answer之外,您还可以使用数组助手来避免将数组转换为集合并返回:Arr::pluck()
Arr::pluck(Project::defaultInvestmentFields, 'investment_name');
推荐阅读
- pyspark - 动态分配变量时,mypy 类型检查显示错误
- docker - 在每个 VCH 的 VIC(VMware vSphere 集成容器)中控制容器入口流量的实际方法是什么?
- reactjs - 使用没有哈希的 URL 的 HashRoute 反应路由器
- javascript - 无论如何在使用html5拖放时用鼠标滚轮滚动页面?
- laravel - Laravel - ErrorException:试图获取非对象的属性'staff_id'
- python - Code Jam 问题:Parent Partnering Returns - 尽管尝试了许多不同类型的测试用例,但似乎无法找出问题所在
- python - 使用 Chaquopy 安装 TensorFlow 时出现“读取超时”
- wpf - WPF 为 TabItem ContentTemplate 动态设置上下文
- node.js - 如何让我的机器人在 Discord 频道 Discord.js 上设置慢速模式
- javascript - WordPress 和 PHP 中的 JavaScript 内部