基本上我只是想知道是否有一种内置的方法,这可能会更快,就像使用array_map回调或其他东西一样:
mingw32-make mingw32-ssl-zlib
答案 0 :(得分:4)
这应该适合你:
只需将NULL
作为第二个参数传递给array_column()
,以将完整数组作为值返回,并使用$column
作为键的第三个参数。
$result = array_column($arr, NULL, $column);
示例输入/输出:
$arr = [
["a" => 1, "b" => 2, "c" => 3],
["a" => 4, "b" => 5, "c" => 6],
["a" => 7, "b" => 8, "c" => 9],
];
$column = "b";
$result = array_column($arr, NULL, $column);
print_r($result);
输出:
Array
(
[2] => Array
(
[a] => 1
[b] => 2
[c] => 3
)
[5] => Array
(
[a] => 4
[b] => 5
[c] => 6
)
[8] => Array
(
[a] => 7
[b] => 8
[c] => 9
)
)