Multidimensional arrays eliminate duplicate values

Source: Internet
Author: User
Suitable for merging arrays to remove duplicate arrays. Mark for yourself, please.
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": "25th volume sixth chapter swept Away",
  10. "Sub_count": 5364424,
  11. "Novel_name": "Reckless and desolate",
  12. "Last_update_time": 1393679718826
  13. },
  14. {
  15. "Classes": "Fantasy",
  16. "GID": 6109786,
  17. "Author": "Tang Three Little",
  18. "Nid": 10079046,
  19. "Last_sort": 1153,
  20. "Last_chapter_name": "The No. 381 chapter begins to act (middle)",
  21. "Sub_count": 3933876,
  22. "Novel_name": "The Peerless Tang Gate",
  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": "The No. 432 chapter carries the daughter-in-law 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": "The No. 2588 Chapter wakes up!" ",
  43. "Sub_count": 2841630,
  44. "Novel_name": "Wu Inverse",
  45. "Last_update_time": 1393605899300
  46. },
  47. {
  48. "Classes": "Fantasy",
  49. "GID": 3701669,
  50. "Author": "Pale Smile Day",
  51. "Nid": 8583556,
  52. "Last_sort": 3427,
  53. "Last_chapter_name": "Chapter 2,225 Peacock King!" ",
  54. "Sub_count": 606473,
  55. "Novel_name": "Wu broken Nine",
  56. "Last_update_time": 1391279170831
  57. },
  58. {
  59. "Classes": "Fantasy",
  60. "GID": 8141499,
  61. "Author": "Wind The World",
  62. "Nid": 9212380,
  63. "Last_sort": 2579,
  64. "Last_chapter_name": "The No. 526 Chapter nine robbery, the war of the Emperor" Seven ",
  65. "Sub_count": 3082857,
  66. "Novel_name": "Proud Kokonoe days",
  67. "Last_update_time": 1393677692614
  68. }
  69. ],
  70. "Cate_book_items": [
  71. {
  72. "Classes": "Fantasy",
  73. "GID": 4711723,
  74. "Author": "Just a little shrimp",
  75. "Nid": 12629406,
  76. "Last_sort": 2603,
  77. "Last_chapter_name": "The No. 2588 Chapter wakes up!" ",
  78. "Sub_count": 2841630,
  79. "Novel_name": "Wu Inverse",
  80. "Last_update_time": 1393605899300
  81. },
  82. {
  83. "Classes": "Fantasy",
  84. "GID": 3701669,
  85. "Author": "Pale Smile Day",
  86. "Nid": 8583556,
  87. "Last_sort": 3427,
  88. "Last_chapter_name": "Chapter 2,225 Peacock King!" ",
  89. "Sub_count": 606473,
  90. "Novel_name": "Wu broken Nine",
  91. "Last_update_time": 1391279170831
  92. },
  93. {
  94. "Classes": "Fantasy",
  95. "GID": 10645516,
  96. "Author": "Chen Dong",
  97. "Nid": 12649548,
  98. "Last_sort": 478,
  99. "Last_chapter_name": "The No. 432 chapter carries the daughter-in-law back to the village",
  100. "Sub_count": 1422482,
  101. "Novel_name": "Perfect World",
  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. ';
  127. ?>
Copy Code
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.