我有一个键数组,我有一个值数组..如何使arrray A的值作为数组B的值的“键”?
array A
[0] => 224
[1] => 77
[2] => 78
[3] => 79
[4] => 80
[5] => 81
[6] => 82
[7] => 76
)
1
array B
Array
(
[0] => Men Shoes
[1] => Fashion Accessories
[2] => Men Apparels
[3] => Shoes & Belts
[4] => Watches & Clocks
[5] => Women Apparels
[6] => Others
[7] => Bags
我想要发生的事情是这样的
array(
[224] => Men Shoes
[77] => Fashion Accessories
[78] => Men Apparells
[79] => Shoes & Belts
[80] => Watches & clocks
[81] => Women Apparels
[82] => Others
[76] => Bags
)
答案 0 :(得分:2)
您可以使用array_combine()
使用keys数组中的值作为键来创建数组 值数组中的值作为相应的值。
答案 1 :(得分:2)
您可以使用array_combine()
您的示例代码。
<?PHP
$array_a = array
(
0 => 224,
1 => 77,
2 => 78,
3 => 79,
4 => 80,
5 => 81,
6 => 82,
7 => 76
);
$array_b = array
(
0 => "Men Shoes",
1 => "Fashion Accessories",
2 => "Men Apparels",
3 => "Shoes & Belts",
4 => "Watches & Clocks",
5 => "Women Apparels",
6 => "Others",
7 => "Bags"
);
$new_array = array_combine($array_a,$array_b);
print_r($new_array);
?>