我的print_r结果如下:
Array ( [0] => A, B, C, D [1] => 15,20,24,19 )
如何让它们像这样:
Array ( [A] => 15 [B] => 20 [C] => 24 [D] => 19 )
非常感谢您的帮助:)
答案 0 :(得分:1)
试试这个:
$a = array('A', 'B', 'C', 'D');
$b = array(15, 20, 24, 19);
$c = array();
foreach ($a as $index => $value) {
if (isset($b[$index])) {
$c[$value] = $b[$index];
}
}
var_dump($c);
答案 1 :(得分:0)
<?php
$myArray = array(
array('A', 'B', 'C', 'D'),
array(15, 20, 24, 19)
);
$combinedArray = array_combine($myArray[0], $myArray[1]);
答案 2 :(得分:0)
尝试用逗号explode()
数组索引,并使用array_combine()
$a = explode(',',$arr[0]);
$b = explode(',',$arr[1]);
$new = array_combine($a,$b);
print_r($new); //Array ( [A] => 15 [ B] => 20 [ C] => 24 [ D] => 19 )
答案 3 :(得分:0)
您需要explode()和array_combine()。假设您的初始数组为$arr
:
$new_arr = array_combine(explode(', ', $arr[0]), explode(',', $arr[1]));