PHP利用多维数组去掉重复值
内容摘要
这篇文章主要为大家详细介绍了PHP利用多维数组去掉重复值,具有一定的参考价值,可以用来参考一下。
文章正文
这篇文章主要为大家详细介绍了PHP利用多维数组去掉重复值,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随php教程的小玲来看看吧!
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | <code class = "language-php" ><?php /* php教程 www.512Pic.com */ $json ='{ "rec_items" : [ { "classes" : "玄幻" , "gid" : 6326585, "author" : "我吃西红柿" , "nid" : 10079306, "last_sort" : 841, "last_chapter_name" : "第二十五卷 第六章 一扫而空" , "sub_count" : 5364424, "novel_name" : "莽荒纪" , "last_update_time" : 1393679718826 }, { "classes" : "玄幻" , "gid" : 6109786, "author" : "唐家三少" , "nid" : 10079046, "last_sort" : 1153, "last_chapter_name" : "第三百八十一章 开始行动(中)" , "sub_count" : 3933876, "novel_name" : "绝世唐门" , "last_update_time" : 1393681654511 }, { "classes" : "玄幻" , "gid" : 10645516, "author" : "辰东" , "nid" : 12649548, "last_sort" : 478, "last_chapter_name" : "第四百三十二章 扛媳妇回村" , "sub_count" : 1422482, "novel_name" : "完美世界" , "last_update_time" : 1393681655610 }, { "classes" : "玄幻" , "gid" : 4711723, "author" : "只是小虾米" , "nid" : 12629406, "last_sort" : 2603, "last_chapter_name" : "第2588章 苏醒!" , "sub_count" : 2841630, "novel_name" : "武逆" , "last_update_time" : 1393605899300 }, { "classes" : "玄幻" , "gid" : 3701669, "author" : "苍笑天" , "nid" : 8583556, "last_sort" : 3427, "last_chapter_name" : "第两千两百二十五章 孔雀王!" , "sub_count" : 606473, "novel_name" : "武破九霄" , "last_update_time" : 1391279170831 }, { "classes" : "玄幻" , "gid" : 8141499, "author" : "风凌天下" , "nid" : 9212380, "last_sort" : 2579, "last_chapter_name" : "第五百二十六章 九劫、天帝之战【七】" , "sub_count" : 3082857, "novel_name" : "傲世九重天" , "last_update_time" : 1393677692614 } ], "cate_book_items" : [ { "classes" : "玄幻" , "gid" : 4711723, "author" : "只是小虾米" , "nid" : 12629406, "last_sort" : 2603, "last_chapter_name" : "第2588章 苏醒!" , "sub_count" : 2841630, "novel_name" : "武逆" , "last_update_time" : 1393605899300 }, { "classes" : "玄幻" , "gid" : 3701669, "author" : "苍笑天" , "nid" : 8583556, "last_sort" : 3427, "last_chapter_name" : "第两千两百二十五章 孔雀王!" , "sub_count" : 606473, "novel_name" : "武破九霄" , "last_update_time" : 1391279170831 }, { "classes" : "玄幻" , "gid" : 10645516, "author" : "辰东" , "nid" : 12649548, "last_sort" : 478, "last_chapter_name" : "第四百三十二章 扛媳妇回村" , "sub_count" : 1422482, "novel_name" : "完美世界" , "last_update_time" : 1393681655610 } ] }'; function mult_unique( $array ) { $return = array (); foreach ( $array as $key => $v ) { if (!in_array( $v , $return )) { $return [ $key ]= $v ; } } return $return ; } $json = get_object_vars(json_decode( $json )); $data = $json [ 'rec_items' ]; $data = array_merge_recursive ( $data , $json [ 'cate_book_items' ]); echo '<pre>' ; print_r( $data ); echo '<br>' ; print_r(mult_unique( $data )); echo '</pre>' ; ?></code> |
注:关于PHP利用多维数组去掉重复值的内容就先介绍到这里,更多相关文章的可以留意
代码注释