二维数组的array_unique函数

关于php的array_unique函数,此函数只适用于一维数组,对多维数组并不适用,以下提供一个二维数组的array_unique函数 

//二维数组去掉重复值
function array_unique_fb($array2D){  
     foreach ($array2D as $v){
         $v = join(“,”,$v);              //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
         $temp[] = $v;
     }

     $temp = array_unique($temp);      //去掉重复的字符串,也就是重复的一维数组
    foreach ($temp as $k => $v){
        $temp[$k] = explode(“,”,$v);       //再将拆开的数组重新组装
    }
    return $temp;
}

原文:http://blog.sina.com.cn/s/blog_60c5cbf50100e4qz.html

Popularity: 8%

No Responses to “二维数组的array_unique函数”

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Website:
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>