Home >php教程 >php手册 >php二维数组去除特定键的重复项

php二维数组去除特定键的重复项

WBOY
WBOYOriginal
2016-06-08 08:49:49799browse

php二维数组去除特定键的重复项 无 //二维数组去除特定键的重复项 public function array_unset($arr,$key){ //$arr-传入数组 $key-判断的key值 //建立一个目标数组 $res = array(); foreach ($arr as $value) { //查看有没有重复项 if(isset($res[$value[$ke

php二维数组去除特定键的重复项
//二维数组去除特定键的重复项
    public function array_unset($arr,$key){   //$arr->传入数组   $key->判断的key值
        //建立一个目标数组
        $res = array();      
        foreach ($arr as $value) {         
           //查看有没有重复项
           if(isset($res[$value[$key]])){
                 //有:销毁
                 unset($value[$key]);
           }
           else{
                $res[$value[$key]] = $value;
           }
        }
        return $res;
    }
Statement:
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