首頁 > 後端開發 > php教程 > 多維數組去掉重複值

多維數組去掉重複值

WBOY
發布: 2016-07-25 08:48:49
原創
901 人瀏覽過
適合合併數組 去除重複數組。 自己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_pter_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. "nnid" 12649548,
  30. "last_sort": 478,
  31. "last_chapter_name": "第四百三十二章扛媳婦回村",
  32. "sub_count": 1422482, "完美🎜> "完美世界",
  33. "last_update_time": 1393681655610
  34. },
  35. {
  36. "classes": "玄幻",
  37. "gid": 4711723, 」只是小蝦米",
  38. "nid": 12629406,
  39. "last_sort": 2603,
  40. "last_chapter_name": "第2588章甦醒! ",
  41. "sub_count": 2841630,
  42. "novel_name": "武逆",
  43. "last_update_time": 1393605899300
  44. },
  45. { ,
  46. "gid": 3701669,
  47. "author": "蒼笑天",
  48. "nid": 85835556,
  49. "last_sort": 3427,
  50. "last_chater_name"兩千二百二十五章孔雀王! ",
  51. "sub_count": 606473,
  52. "novel_name": "武破九霄",
  53. "last_update_time": 1391279170831
  54. },
  55. " "gid": 8141499,
  56. "author": "風凌天下",
  57. "nid": 9212380,
  58. "last_sort": 2579,
  59. "last_chapter_name"第五百二十六章九劫、天帝之戰【七】",
  60. "sub_count": 3082857,
  61. "novel_name": "傲世九重天",
  62. "last_update_time": 1393677692614 }
  63. ],
  64. "cate_book_items": [
  65. {
  66. "classes": "玄幻",
  67. "gid": 4711723,
  68. "author": "只是小蝦米",
  69. "nid": 12629406,
  70. "last_sort": 2603,
  71. "last_chapter_name": "第2588章甦醒! ",
  72. "sub_count": 2841630,
  73. "novel_name": "武逆",
  74. "last_update_time": 1393605899300
  75. },
  76. {
  77. ,
  78. "gid": 3701669,
  79. "author": "蒼笑天",
  80. "nid": 85835556,
  81. "last_sort": 3427,
  82. "last_chater_name"兩千二百二十五章孔雀王!",
  83. "sub_count": 606473,
  84. "novel_name": "武破九霄",
  85. "last_update_time": 1391279170831
  86. },
  87. " "gid": 10645516,
  88. "author": "辰東",
  89. "nid": 12649548,
  90. "last_sort": 478,
  91. "last_chater_name"四百三十二章扛媳婦回村",
  92. "sub_count": 1422482,
  93. "novel_name": "完美世界",
  94. "last_update_time": 1393681655610
  95. }
  96. }
  97. }';
  98. function mult_unique($array)
  99. {
  100. $return = array();
  101. foreach($array as $key=>$v)
  102. {
  103. if(!in_array($v, $return))
  104. {
  105. $return[$key]=$v;
  106. }
  107. }
  108. return $return;
  109. }
  110. $json = get_object_vars(json_decode($json));
  111. $data = $json['rec_items'];
  112. $data = array_merge_recursive($data, $json[]cate_book ]);
  113. echo '
    ';
    登入後複製
  114. print_r($data);
  115. echo '
    ';
  116. print_r(mult_unique($data));
  117. echo '';
  118. ?>
複製程式碼

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