首頁 > 後端開發 > php教程 > 怎样删除二维数组中相同的一位数组 并保持相同键名 求大神写个函数

怎样删除二维数组中相同的一位数组 并保持相同键名 求大神写个函数

WBOY
發布: 2016-06-06 20:40:27
原創
943 人瀏覽過

<code>Array
(
    [0] => Array
        (
            [year] => 2013-2014
            [term] => 1
            [course_code] => 00008069
            [course_name] => 咖啡世界
            [course_nature] => 任意选修
            [course_attribution] => 人文素养类
            [credit] => 2.0
            [point] => 4.1
            [grade] => 91
            [minor_tag] => 0
            [makeup_grade] =>  
            [rebuild_grade] =>  
            [begin_college] => 旅游文化产业学院
            [remark] =>  
            [rebuild_tag] => 0
            [0] => 77
            [1] => 2
        )

    [1] => Array
        (
            [year] => 2013-2014
            [term] => 1
            [course_code] => 00008069
            [course_name] => 咖啡世界
            [course_nature] => 任意选修
            [course_attribution] => 人文素养类
            [credit] => 2.0
            [point] => 4.1
            [grade] => 91
            [minor_tag] => 0
            [makeup_grade] =>  
            [rebuild_grade] =>  
            [begin_college] => 旅游文化产业学院
            [remark] =>  
            [rebuild_tag] => 0
            [0] => 77
            [1] => 2
        )

    [2] => Array
        (
            [year] => 2013-2014
            [term] => 1
            [course_code] => 00008069
            [course_name] => 咖啡世界
            [course_nature] => 任意选修
            [course_attribution] => 人文素养类
            [credit] => 2.0
            [point] => 4.1
            [grade] => 91
            [minor_tag] => 0
            [makeup_grade] =>  
            [rebuild_grade] =>  
            [begin_college] => 旅游文化产业学院
            [remark] =>  
            [rebuild_tag] => 0
            [0] => 77
            [1] => 2
        )

)

如上面  怎样让它变成
Array
(
    [0] => Array
        (
            [year] => 2013-2014
            [term] => 1
            [course_code] => 00008069
            [course_name] => 咖啡世界
            [course_nature] => 任意选修
            [course_attribution] => 人文素养类
            [credit] => 2.0
            [point] => 4.1
            [grade] => 91
            [minor_tag] => 0
            [makeup_grade] =>  
            [rebuild_grade] =>  
            [begin_college] => 旅游文化产业学院
            [remark] =>  
            [rebuild_tag] => 0
            [0] => 77
            [1] => 2
        )
}
</code>
登入後複製
登入後複製

回复内容:

<code>Array
(
    [0] => Array
        (
            [year] => 2013-2014
            [term] => 1
            [course_code] => 00008069
            [course_name] => 咖啡世界
            [course_nature] => 任意选修
            [course_attribution] => 人文素养类
            [credit] => 2.0
            [point] => 4.1
            [grade] => 91
            [minor_tag] => 0
            [makeup_grade] =>  
            [rebuild_grade] =>  
            [begin_college] => 旅游文化产业学院
            [remark] =>  
            [rebuild_tag] => 0
            [0] => 77
            [1] => 2
        )

    [1] => Array
        (
            [year] => 2013-2014
            [term] => 1
            [course_code] => 00008069
            [course_name] => 咖啡世界
            [course_nature] => 任意选修
            [course_attribution] => 人文素养类
            [credit] => 2.0
            [point] => 4.1
            [grade] => 91
            [minor_tag] => 0
            [makeup_grade] =>  
            [rebuild_grade] =>  
            [begin_college] => 旅游文化产业学院
            [remark] =>  
            [rebuild_tag] => 0
            [0] => 77
            [1] => 2
        )

    [2] => Array
        (
            [year] => 2013-2014
            [term] => 1
            [course_code] => 00008069
            [course_name] => 咖啡世界
            [course_nature] => 任意选修
            [course_attribution] => 人文素养类
            [credit] => 2.0
            [point] => 4.1
            [grade] => 91
            [minor_tag] => 0
            [makeup_grade] =>  
            [rebuild_grade] =>  
            [begin_college] => 旅游文化产业学院
            [remark] =>  
            [rebuild_tag] => 0
            [0] => 77
            [1] => 2
        )

)

如上面  怎样让它变成
Array
(
    [0] => Array
        (
            [year] => 2013-2014
            [term] => 1
            [course_code] => 00008069
            [course_name] => 咖啡世界
            [course_nature] => 任意选修
            [course_attribution] => 人文素养类
            [credit] => 2.0
            [point] => 4.1
            [grade] => 91
            [minor_tag] => 0
            [makeup_grade] =>  
            [rebuild_grade] =>  
            [begin_college] => 旅游文化产业学院
            [remark] =>  
            [rebuild_tag] => 0
            [0] => 77
            [1] => 2
        )
}
</code>
登入後複製
登入後複製

php array_merge

<code><?php // http://3v4l.org/LOqSW
function unique($arr) {
    foreach($arr as $k => $v) $arr[$k] = serialize($v);
    $arr = array_unique($arr);
    foreach($arr as $k => $v) $arr[$k] = unserialize($v);
    return $arr;
}

$jwcUpdate = unique($jwcUpdate);
print_r($jwcUpdate);
</code>
登入後複製
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板