欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

多维数组去掉重复值

程序员文章站 2022-06-10 21:46:25
...
适合合并数组 去除重复数组。 自己Mark一下
www.appleshu.com
  1. $json='{
  2. "rec_items": [
  3. {
  4. "classes": "玄幻",
  5. "gid": 6326585,
  6. "author": "我吃西红柿",
  7. "nid": 10079306,
  8. "last_sort": 841,
  9. "last_chapter_name": "第二十五卷 第六章 一扫而空",
  10. "sub_count": 5364424,
  11. "novel_name": "莽荒纪",
  12. "last_update_time": 1393679718826
  13. },
  14. {
  15. "classes": "玄幻",
  16. "gid": 6109786,
  17. "author": "唐家三少",
  18. "nid": 10079046,
  19. "last_sort": 1153,
  20. "last_chapter_name": "第三百八十一章 开始行动(中)",
  21. "sub_count": 3933876,
  22. "novel_name": "绝世唐门",
  23. "last_update_time": 1393681654511
  24. },
  25. {
  26. "classes": "玄幻",
  27. "gid": 10645516,
  28. "author": "辰东",
  29. "nid": 12649548,
  30. "last_sort": 478,
  31. "last_chapter_name": "第四百三十二章 扛媳妇回村",
  32. "sub_count": 1422482,
  33. "novel_name": "完美世界",
  34. "last_update_time": 1393681655610
  35. },
  36. {
  37. "classes": "玄幻",
  38. "gid": 4711723,
  39. "author": "只是小虾米",
  40. "nid": 12629406,
  41. "last_sort": 2603,
  42. "last_chapter_name": "第2588章 苏醒!",
  43. "sub_count": 2841630,
  44. "novel_name": "武逆",
  45. "last_update_time": 1393605899300
  46. },
  47. {
  48. "classes": "玄幻",
  49. "gid": 3701669,
  50. "author": "苍笑天",
  51. "nid": 8583556,
  52. "last_sort": 3427,
  53. "last_chapter_name": "第两千两百二十五章 孔雀王!",
  54. "sub_count": 606473,
  55. "novel_name": "武破九霄",
  56. "last_update_time": 1391279170831
  57. },
  58. {
  59. "classes": "玄幻",
  60. "gid": 8141499,
  61. "author": "风凌天下",
  62. "nid": 9212380,
  63. "last_sort": 2579,
  64. "last_chapter_name": "第五百二十六章 九劫、天帝之战【七】",
  65. "sub_count": 3082857,
  66. "novel_name": "傲世九重天",
  67. "last_update_time": 1393677692614
  68. }
  69. ],
  70. "cate_book_items": [
  71. {
  72. "classes": "玄幻",
  73. "gid": 4711723,
  74. "author": "只是小虾米",
  75. "nid": 12629406,
  76. "last_sort": 2603,
  77. "last_chapter_name": "第2588章 苏醒!",
  78. "sub_count": 2841630,
  79. "novel_name": "武逆",
  80. "last_update_time": 1393605899300
  81. },
  82. {
  83. "classes": "玄幻",
  84. "gid": 3701669,
  85. "author": "苍笑天",
  86. "nid": 8583556,
  87. "last_sort": 3427,
  88. "last_chapter_name": "第两千两百二十五章 孔雀王!",
  89. "sub_count": 606473,
  90. "novel_name": "武破九霄",
  91. "last_update_time": 1391279170831
  92. },
  93. {
  94. "classes": "玄幻",
  95. "gid": 10645516,
  96. "author": "辰东",
  97. "nid": 12649548,
  98. "last_sort": 478,
  99. "last_chapter_name": "第四百三十二章 扛媳妇回村",
  100. "sub_count": 1422482,
  101. "novel_name": "完美世界",
  102. "last_update_time": 1393681655610
  103. }
  104. ]
  105. }';
  106. function mult_unique($array)
  107. {
  108. $return = array();
  109. foreach($array as $key=>$v)
  110. {
  111. if(!in_array($v, $return))
  112. {
  113. $return[$key]=$v;
  114. }
  115. }
  116. return $return;
  117. }
  118. $json = get_object_vars(json_decode($json));
  119. $data = $json['rec_items'];
  120. $data = array_merge_recursive($data, $json['cate_book_items']);
  121. echo '
    ';
  122. print_r($data);
  123. echo '
    ';
  124. print_r(mult_unique($data));
  125. echo '';
  126. ?>
复制代码