将数组键复制到另一个现有数组键

Kar*_*ong 0 php arrays

我有2个数组,一个有键,另一个有数字键,我怎么能复制它们的键,按照确切的顺序替换数字键?

带数字键的数组

Array
(
    [0] => ABCDEFG
    [1] => This is my description
    [2] => 12.00
    [3] => 30.00
    [4] => My supplier
    [5] => My brand
    [6] => Shoes
    [7] => 

)
Run Code Online (Sandbox Code Playgroud)

数组2

Array
(
    [productcode] => Product Code
    [productitemdesc] => Description
    [retailsalesprice] => Selling Price
    [currentcost] => Unit Cost
    [supplier] => Supplier
    [productbrand] => Brand
    [productcategory] => Category
    [productgroup] => Group
)
Run Code Online (Sandbox Code Playgroud)

我想要这样的东西

Array
    (
        [productcode] => ABCDEFG
        [productitemdesc] => This is my description
        [retailsalesprice] => 12.00
        [currentcost] => 30.00
        [supplier] => My Supplier
        [productbrand] => My Brand
        [productcategory] => Shoes
        [productgroup] =>
    )
Run Code Online (Sandbox Code Playgroud)

是否有任何现有的功能可用于PHP?试过array_fill_keys但似乎不是我想要的.

Dan*_*Dan 5

您可以使用该函数array_combine()将第二个数组中的键(对于以下调用的示例$array_keys)与来自第一个数组(被调用$array_values)的值组合在一起:

例:

$combined = array_combine(array_keys($array_keys), $array_values);
print_r($combined);
Run Code Online (Sandbox Code Playgroud)

这将打印出与您描述的完全相同的阵列.