2013-12-20 112 views

回答

1

使用array_replace()

$a = array([0] => 0 [1] => 3); 
$b = array([0] => Done [1] => Pending) ; 

$result = array_replace($a, $b); 

数组替换,用$ b的值替换$ b中具有相同键的$ a的所有值。

6

用途:array_combine()

$result = array_combine($a, $b); 
print_r($result); // => Array ([0] => Done [1] => Pending) 

Demo.

0

请再试此

$a=array (0=>0,1=>3); 
$b=array (0=>'Done',1=>'Pending'); 
$c= array_merge($a,$b); 

echo "<br/> a: ";print_r($a); 
echo "<br/> b: ";print_r($b); 
echo "<br/> c: ";print_r($b); 

OUTPUT:

一个:阵列([0] => 0 [1] => 3)

B:阵列([0] =>完成[1] =>待定)

C:阵列([0] =>完成[1] =>待定)

与在线编辑器尝试[测测你的PHP 。代码在网上,就在这里]

http://writecodeonline.com/php/

例也http://www.php.net/manual/en/function.array-merge.php

0

如果你的两个数组的大小相同那就试试这个:

$a =array(0 => 0, 1 => 3); 
$b=array (0 => "Done", 1 => "Pending") ; 

$result = array(); 
for($i=0 ; $i < count($a);$i++){ 
    $result[$a[$i]] = $b[$i]; 
} 
print_r($result); 
相关问题