Maison >développement back-end >tutoriel php > 数组有关问题 求大侠给个方法
数组问题 求大侠给个方法
$a = Array
(
[0] => 3
[1] => 1
[2] => 2
[3] => 7
)
$b = Array
(
[1] => Emross War
[2] => Roman Empire
[3] => Avalon Wars
[7] => 掌上三国
[9] => 罗马(91)
[10] => Space Dominions
[11] => 腾讯三国
[12] => Vampire War
[15] => 三国英雄传
[17] => 掌上水浒
)
$a数组中的值是$b 的键值
那我如何得到
$c = Array
(
[1] => Emross War
[2] => Roman Empire
[3] => Avalon Wars
[7] => 掌上三国
)
求大侠给个答案
$a = Array<br /> (<br /> 0 => 3,<br /> 1 => 1,<br /> 2 => 2,<br /> 3 => 7<br /> );<br /> <br /> $b = Array<br /> (<br /> 1 => 'Emross War',<br /> 2 => 'Roman Empire',<br /> 3 => 'Avalon Wars',<br /> 7 => '掌上三国',<br /> 9 => '罗马(91)',<br /> 10 =>'Space Dominions',<br /> 11 =>'腾讯三国',<br /> 12 =>'Vampire War',<br /> 15 =>'三国英雄传',<br /> 17 =>'掌上水浒'<br /> );<br /> foreach($a as $k){<br /> $c[$k]=$b[$k];<br /> }<br /> ksort($c);<br /> print_r($c);
sort($a); // 将数组 $a 按值升序排列<br /> $c = array(); //定义一个结果数组<br /> foreach($a as $k) { // 依次从数组 $b 中取值<br /> $c[$k] = $b[$k];<br /> }
<br> <br> $a = Array<br> (<br> '0' => 3,<br> '1' => 1,<br> '2' => 2,<br> '3' => 7<br> );<br> <br> $b = Array<br> (<br> '1' => 'Emross War',<br> '2' => 'Roman Empire',<br> '3' => 'Avalon Wars',<br> '7' => '掌上三国',<br> '9' => '罗马(91)',<br> '10' => 'Space Dominions',<br> '11' => '腾讯三国',<br> '12' => 'Vampire War',<br> '15' => '三国英雄传',<br> '17' => '掌上水浒',<br> );<br> $c = array_flip($a); //array_flip -- 交换数组中的键和值 <div class="clear"> </div>