php’s function to remove duplicate values from an array can also be understood as removing duplicate values from an array.
/** * 给数组排重 * 与array_unique函数的区别:它要求val是字符串,而这个可以是数组/对象 * * @param $arr 要排重的数组 * @param $reserveKey 是否保留原来的Key * @return array */ function m_ArrayUnique($arr,$reserveKey=false){ if(is_array($arr) && !empty($arr)){ foreach($arr as $key=>$value){ $tmpArr[$key]=serialize($value).''; } $tmpArr=array_unique($tmpArr); $arr=array(); foreach($tmpArr as $key=>$value){ if($reserveKey){ $arr[$key]=unserialize($value); }else{ $arr[]=unserialize($value); } } } return $arr; }
For how to remove duplicate values from a two-dimensional array, you can refer to: Summary of methods for removing duplicate values from a two-dimensional array in PHP
The above is the function to remove duplicate values from an array_PHP Tutorial For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!