2013-12-20 114 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); 
相關問題