开发者社区> 问答> 正文

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

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
)
}

大神给支个招,拜谢

展开
收起
小旋风柴进 2016-03-06 09:55:05 3475 0
1 条回答
写回答
取消 提交回答
  • 希望对你有帮助,望采纳

    $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>";
    
    2019-07-17 18:54:03
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载