【发布时间】:2020-08-04 08:07:58
【问题描述】:
我有一个包含这个值的二维数组:
[
'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'));
【问题讨论】: