我有这个阵列......
Array
(
[result] => Success
[finals] => Array
(
[0] => Array
(
[id] => 633
[name] => RESULT84
)
[0] => Array
(
[id] => 766
[name] => RESULT2
)
[0] => Array
(
[id] => 22
[name] => RESULT1
)
)
)
我正在提取这样的名字......
$names = array_column($data['finals'], 'name');
print_r($names);
这给了我......
Array
(
[0] => RESULT84
[1] => RESULT2
[2] => RESULT1
)
我的问题是如何修改它以便我得到这个......
Array
(
[RESULT84] => RESULT84
[RESULT2] => RESULT2
[RESULT1] => RESULT1
)
像array_fill_keys这样的东西最好吗?
答案 0 :(得分:7)
将第三个参数name
传递到array_column
以使其成为关键
$names = array_column($data['finals'], 'name','name');
print_r($names);
答案 1 :(得分:2)
{{1}}