我有以下内容:
([0] => 3 [1] => 2 [2] => 12 [3] => 6 [4] => 8 [5] => 7 [6] = > 9 [7] => 10 [8] => 5 [9] => 4)
我想使用每个值作为关键字:
([0] => 7 [1] => 2 [2] => 10 [3] => 3 [4] => 5 [5] => 6 [6] = > 11 [7] => 9 [8] => 4 [9] => 8)
我试过这个:
foreach ($iOrder as $i)
{
$pOrder[$i] = $pOrder[$p];
$p++;
}
我明白了:
([12] => 2 [10] => 6 [5] => 5 [4] => 7)
有什么想法?
答案 0 :(得分:11)
答案 1 :(得分:0)
Frist数组, $ arr1 ,
([0] => 3 [1] => 2 [2] => 12 [3] => 6 [4] => 8 [5] => 7 [6] => 9 [7] => 10 [8] => 5 [9] => 4)
第二个数组,$ arr2 , ([0] => 7 [1] => 2 [2] => 10 [3] => 3 [4] => 5 [5] => 6 [6] => 11 [7] => 9 [8] => 4 [9] => 8)
如果我理解正确,你想在$ arr2中使用$ arr1的值作为键。
$values = array_values($arr1);
=>这将为您提供$ arr1的值。
你可以使用array_combine($keys, $values);
所以得到的数组将是,
$result_arr = array_combine(array_values($arr1), array_values($arr2));
但是,如果两个数组中的项不同,则可能无法正常工作。