一个数组的php值到另一个数组的键

时间:2011-01-13 12:46:29

标签: php arrays

我有2个阵列

$arr1 = Array
(
    [0] => 12
    [1] => 4
    [2] => 8
    [3] => xx
    [4] => 1
    [5] => 1year
    [6] => 7
)
$arr2 = Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 6
    [6] => 7
)

我想在$ arr1中创建一个值为a2的新数组作为键。 我的结果数组应该是这样的

$arr3 = Array
(
    [1] => 12
    [2] => 4
    [3] => 8
    [4] => xx
    [5] => 1
    [6] => 1year
    [7] => 7
)

3 个答案:

答案 0 :(得分:6)

$arr3 = array_combine($arr2, $arr1);
print_r($arr3);

下次请先咨询manual

答案 1 :(得分:3)

您需要array_combine

答案 2 :(得分:0)

关于查看php手册的内容是什么?并找到array_combine($keys, $values)