时间:2021-07-01 10:21:17 帮助过:36人阅读
$arr = array(
'175' => '金针菇'
'100' => '银针菇'
);
$arr2 = array(
'65' => '白萝卜'
'67' => '黑萝卜'
'84' => '黄萝卜'
'100' => '银针菇'
'90' => '大萝卜'
'175' => '金针菇'
);
最后的效果是这样子滴:
$arr3 = array(
'175' => '金针菇'
'100' => '银针菇'
'65' => '白萝卜'
'67' => '黑萝卜'
'84' => '黄萝卜'
'90' => '大萝卜'
);
请教,这样的算法该怎么实现?
举个栗子:
$arr = array(
'175' => '金针菇'
'100' => '银针菇'
);
$arr2 = array(
'65' => '白萝卜'
'67' => '黑萝卜'
'84' => '黄萝卜'
'100' => '银针菇'
'90' => '大萝卜'
'175' => '金针菇'
);
最后的效果是这样子滴:
$arr3 = array(
'175' => '金针菇'
'100' => '银针菇'
'65' => '白萝卜'
'67' => '黑萝卜'
'84' => '黄萝卜'
'90' => '大萝卜'
);
请教,这样的算法该怎么实现?
这个问题已关闭,自己写出来了,提问的时候想复杂了,缓和了之后才知道原来这么简单,贴下代码:
foreach ($arr2 as $key => $value) {
if(!in_array($value, $arr)) {
$arr[$key] = $value;
}
}
var_dump($arr);
return($arr + $arr2);