舉個栗子:
<code>$arr = array( '175' => '金针菇' '100' => '银针菇' ); $arr2 = array( '65' => '白萝卜' '67' => '黑萝卜' '84' => '黄萝卜' '100' => '银针菇' '90' => '大萝卜' '175' => '金针菇' ); </code>
最後的效果是這樣子滴:
<code>$arr3 = array( '175' => '金针菇' '100' => '银针菇' '65' => '白萝卜' '67' => '黑萝卜' '84' => '黄萝卜' '90' => '大萝卜' );</code>
請教,這樣的演算法該怎麼實現?
舉個栗子:
<code>$arr = array( '175' => '金针菇' '100' => '银针菇' ); $arr2 = array( '65' => '白萝卜' '67' => '黑萝卜' '84' => '黄萝卜' '100' => '银针菇' '90' => '大萝卜' '175' => '金针菇' ); </code>
最後的效果是這樣子滴:
<code>$arr3 = array( '175' => '金针菇' '100' => '银针菇' '65' => '白萝卜' '67' => '黑萝卜' '84' => '黄萝卜' '90' => '大萝卜' );</code>
請教,這樣的演算法該怎麼實現?
這個問題關閉,自己寫出來了,提問的時候想複雜了,緩和了之後才知道原來這麼簡單,貼下程式碼:
<code>foreach ($arr2 as $key => $value) { if(!in_array($value, $arr)) { $arr[$key] = $value; } } var_dump($arr);</code>
<code>return($arr + $arr2);</code>