我可以从数组内部读取数组键,请建议php函数而不是foreach循环,因为我试图尽量避免循环吗?
代码如下所示:
array_fill_keys(array('a','b','c', 'd'),array(
'action'=>'getUserLongTermCategoriesAction',
'params'=> 'place key here',
)
答案 0 :(得分:1)
检查一下。
$arr = array('a','b','c','d');
$temp = array_map(function ($keys) {
return array(
'action'=>'getUserLongTermCategoriesAction',
'params'=> $keys,
);
}, $arr);
$result = array_combine($arr, $temp);
输出:
Array
(
[a] => Array
(
[action] => getUserLongTermCategoriesAction
[params] => a
)
[b] => Array
(
[action] => getUserLongTermCategoriesAction
[params] => b
)
[c] => Array
(
[action] => getUserLongTermCategoriesAction
[params] => c
)
[d] => Array
(
[action] => getUserLongTermCategoriesAction
[params] => d
)
)