从常规数组中创建具有相等键和值的assoc数组 [英] Create an assoc array with equal keys and values from a regular array
本文介绍了从常规数组中创建具有相等键和值的assoc数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个看起来像
$numbers = array('first', 'second', 'third');
我想有一个函数,它将这个数组作为输入并返回一个看起来像这样的数组:
I want to have a function that will take this array as input and return an array that would look like:
array(
'first' => 'first',
'second' => 'second',
'third' => 'third'
)
我想知道是否可以使用array_walk_recursive
或类似的东西...
I wonder if it is possible to use array_walk_recursive
or something similar...
推荐答案
您可以使用 array_combine
函数,如下所示:
You can use the array_combine
function, like so:
$numbers = array('first', 'second', 'third');
$result = array_combine($numbers, $numbers);
这篇关于从常规数组中创建具有相等键和值的assoc数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文