阡陌博客 - 合并数组
type: channel
link: https://www.kinmor.com/tag/合并数组/
items: 合并两个一维数组，去掉重复元素

合并两个一维数组，去掉重复元素
type: item
date: 2020-08-15T12:51:00+08:00
description: //合并两个一维数组，去掉重复元素 function arraymerge($arr1=array(),$arr2=array(),$returnarr=array()){ if(!empty($arr1) && is_array($arr1)){ foreach($arr1 as $key=>$val){ $returnarr[] = $val; } } if(!empty($arr2) && is_array($arr2)){ if(!empty($returnarr)){ foreach($arr2 as $k=>$v){ $flag = false; foreach($returnarr as $ke=>$va){ if($va == $v){ $flag = true; } } if(!$flag){ $returnarr[] = $v; } } }else{ if(!empty($arr2) && is_array($arr2)){ foreach($arr2 as $key2=>$val2){ $returnarr[] = $val2; } } } } return $returnarr; }