Home  >  Article  >  Backend Development  >  Remove duplicate values ​​from multidimensional array

Remove duplicate values ​​from multidimensional array

WBOY
WBOYOriginal
2016-07-25 08:48:49884browse
Suitable for merging arrays and removing duplicate arrays. Mark yourself
www.appleshu.com
  1. $json='{
  2. "rec_items": [
  3. {
  4. "classes": "Fantasy",
  5. "gid": 6326585,
  6. "author": "I eat tomatoes",
  7. "nid": 10079306,
  8. "last_sort": 841,
  9. "last_chapter_name": "Chapter 6 of Volume 25 Swept Away",
  10. "sub_count": 5364424,
  11. "novel_name": "The Wilderness ",
  12. "last_update_time": 1393679718826
  13. },
  14. {
  15. "classes": "Fantasy",
  16. "gid": 6109786,
  17. "author": "Tang Jia San Shao",
  18. "nid": 10079046,
  19. "last_sort" : 1153,
  20. "last_chapter_name": "Chapter 381 Begins Action (Part 2)",
  21. "sub_count": 3933876,
  22. "novel_name": "Peerless Tang Sect",
  23. "last_update_time": 1393681654511
  24. },
  25. {
  26. "classes": "Fantasy",
  27. "gid": 10645516,
  28. "author": "Chen Dong",
  29. "nid": 12649548,
  30. "last_sort": 478,
  31. "last_chapter_name": "Fourth Chapter 132: Carrying the Wife Back to the Village",
  32. "sub_count": 1422482,
  33. "novel_name": "Perfect World",
  34. "last_update_time": 1393681655610
  35. },
  36. {
  37. "classes": "Fantasy",
  38. " gid": 4711723,
  39. "author": "Just a little shrimp",
  40. "nid": 12629406,
  41. "last_sort": 2603,
  42. "last_chapter_name": "Chapter 2588 Wake up! ",
  43. "sub_count": 2841630,
  44. "novel_name": "武Ni",
  45. "last_update_time": 1393605899300
  46. },
  47. {
  48. "classes": "fantasy",
  49. "gid": 3701669,
  50. "author" : "Cang Xiaotian",
  51. "nid": 8583556,
  52. "last_sort": 3427,
  53. "last_chapter_name": "Chapter 2225 The Peacock King! ",
  54. "sub_count": 606473,
  55. "novel_name": "武波九鄄",
  56. "last_update_time": 1391279170831
  57. },
  58. {
  59. "classes": "fantasy",
  60. "gid": 8141499,
  61. "author ": "Feng Ling Tian Xia",
  62. "nid": 9212380,
  63. "last_sort": 2579,
  64. "last_chapter_name": "Chapter 526 Nine Tribulations, Battle of the Emperor of Heaven [Seven]",
  65. "sub_count" : 3082857, 2 "NOVEL_NAME": "Ao Shi Nine Heaven",
  66. "Last_update_time": 1393677692614
  67. }
  68. ],
  69. "Cate_Book_items": [
  70. {
  71. "" fantasy ",
  72. " gid ": 47777 11723,, "author": "Just a little shrimp",
  73. "nid": 12629406,
  74. "last_sort": 2603,
  75. "last_chapter_name": "Chapter 2588 Wake up! ",
  76. "sub_count": 2841630,
  77. "novel_name": "武Ni",
  78. "last_update_time": 1393605899300
  79. },
  80. {
  81. "classes": "fantasy",
  82. "gid": 3701669,
  83. "author" : "Cang Xiaotian",
  84. "nid": 8583556,
  85. "last_sort": 3427,
  86. "last_chapter_name": "Chapter 2225 The Peacock King!",
  87. "sub_count": 606473,
  88. "novel_name": "武波九鄄",
  89. "last_update_time": 1391279170831
  90. },
  91. {
  92. "classes": "Fantasy",
  93. "gid": 10645516,
  94. "author ": "Chen Dong",
  95. "nid": 12649548,
  96. "last_sort": 478,
  97. "last_chapter_name": "Chapter 432 Carrying the Wife Back to the Village",
  98. "sub_count": 1422482,
  99. "novel_name ": "Perfect World",
  100. "last_update_time": 1393681655610
  101. }
  102. ]
  103. }';
  104. function mult_unique($array)
  105. {
  106. $return = array();
  107. foreach($array as $key=> $v)
  108. {
  109. if(!in_array($v, $return))
  110. {
  111. $return[$key]=$v;
  112. }
  113. }
  114. return $return;
  115. }
  116. $json = get_object_vars(json_decode ($json));
  117. $data = $json['rec_items'];
  118. $data = array_merge_recursive($data, $json['cate_book_items']);
  119. echo '
    ';</li>
    <li>print_r($ data);</li>
    <li>echo '<br>';</li>
    <li>print_r(mult_unique($data));</li>
    <li>echo '
    ';
  120. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn