Home > Backend Development > PHP Tutorial > 二维数组去除重复值和array_unique函数

二维数组去除重复值和array_unique函数

WBOY
Release: 2016-06-20 13:03:56
Original
1059 people have browsed it

对于一维数组去除重复值的方法,是可以直接使用php系统函数array_unique,但是这个函数不能对多维数组去除重复值。

下面分享一个可以去除二维数组的重复值的函数。

//二维数组去掉重复值

function array_unique_fb($array2D){  <br />	foreach ($array2D as $v){<br />		$v=join(',',$v);//降维,也可以用implode,将一维数组转换为用逗号连接的字符串<br />		$temp[]=$v;<br />	}<br />	$temp=array_unique($temp);//去掉重复的字符串,也就是重复的一维数组<br />	foreach ($temp as $k => $v){<br />		$temp[$k]=explode(',',$v);//再将拆开的数组重新组装<br />	}<br />	return $temp;<br />}
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template