怎样删除二维数组中相同的一位数组 并保持相同键名呢?-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

怎样删除二维数组中相同的一位数组 并保持相同键名呢?

小旋风柴进 2016-03-06 09:55:05 1716
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
)
}

大神给支个招,拜谢

分享到
取消 提交回答
全部回答(1)
  • 小旋风柴进
    2019-07-17 18:54:03

    希望对你有帮助,望采纳

    $arr=array(
            0=>array(
            'name'=>"xxx",
            'age'=>23,
            'school'=>"yyyy大学"
    ),
            1=>array(
            'name'=>"xxx",
            'age'=>23,
            'school'=>"yyyy大学"
    ),
            2=>array(
                    'name'=>"xxx",
                    'age'=>23,
                    'school'=>"yyyy大学"
            )
            );
    $delete_key=0;//需要找的重复的数组的下标值
    $value=$arr[$delete_key];//获取其值
    $key=array_keys($arr,$value);//需要同样的值的下标
    foreach ($key as $k=>$v)
    {
        if($v!=$delete_key)//第一个值不删,其它的删除
            unset($arr[$v]);
    }
    echo"<pre>";
    var_dump($arr);
    echo"</pre>";
    
    0 0
云计算
使用钉钉扫一扫加入圈子
+ 订阅

时时分享云计算技术内容,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。

推荐文章