PHP multidimensional Array Remove duplicate value sample share _php instance

Source: Internet
Author: User

Copy Code code as follows:

<?php
$json = ' {

"Rec_items": [
{
"Classes": "Fantasy",
"GID": 6326585,
"Author": "I eat tomatoes",
"Nid": 10079306,
"Last_sort": 841,
"Last_chapter_name": "25th Volume sixth chapter dispelled",
"Sub_count": 5364424,
"Novel_name": "The Wild Wasteland",
"Last_update_time": 1393679718826
},
{
"Classes": "Fantasy",
"GID": 6109786,
"Author": "Tanggu three Less",
"Nid": 10079046,
"Last_sort": 1153,
"Last_chapter_name": "No. 381 chapter begins action (middle)",
"Sub_count": 3933876,
"Novel_name": "The Peerless Tang Door",
"Last_update_time": 1393681654511
},
{
"Classes": "Fantasy",
"GID": 10645516,
"Author": "Chen Dong",
"Nid": 12649548,
"Last_sort": 478,
"Last_chapter_name": "The No. 432 chapter carries daughter-in-law back to the village",
"Sub_count": 1422482,
"Novel_name": "The Perfect World",
"Last_update_time": 1393681655610
},
{
"Classes": "Fantasy",
"GID": 4711723,
"Author": "Just little Shrimp",
"Nid": 12629406,
"Last_sort": 2603,
"Last_chapter_name": "The No. 2588 Chapter wakes up!" ",
"Sub_count": 2841630,
"Novel_name": "Wu-Contra",
"Last_update_time": 1393605899300
},
{
"Classes": "Fantasy",
"GID": 3701669,
"Author": "Cang Smile Day",
"Nid": 8583556,
"Last_sort": 3427,
"Last_chapter_name": "Chapter 2,225 Peacock King!" ",
"Sub_count": 606473,
"Novel_name": "Wu Broken Jiuxiao",
"Last_update_time": 1391279170831
},
{
"Classes": "Fantasy",
"GID": 8141499,
"Author": "The Wind Ling World",
"Nid": 9212380,
"Last_sort": 2579,
"Last_chapter_name": "The No. 526 Chapter nine robbery, the war of the Emperor of Heaven" Seven "",
"Sub_count": 3082857,
"Novel_name": "Ao bougainvillea days",
"Last_update_time": 1393677692614
}
],
"Cate_book_items": [
{
"Classes": "Fantasy",
"GID": 4711723,
"Author": "Just little Shrimp",
"Nid": 12629406,
"Last_sort": 2603,
"Last_chapter_name": "The No. 2588 Chapter wakes up!" ",
"Sub_count": 2841630,
"Novel_name": "Wu-Contra",
"Last_update_time": 1393605899300
},
{
"Classes": "Fantasy",
"GID": 3701669,
"Author": "Cang Smile Day",
"Nid": 8583556,
"Last_sort": 3427,
"Last_chapter_name": "Chapter 2,225 Peacock King!" ",
"Sub_count": 606473,
"Novel_name": "Wu Broken Jiuxiao",
"Last_update_time": 1391279170831
},
{
"Classes": "Fantasy",
"GID": 10645516,
"Author": "Chen Dong",
"Nid": 12649548,
"Last_sort": 478,
"Last_chapter_name": "The No. 432 chapter carries daughter-in-law back to the village",
"Sub_count": 1422482,
"Novel_name": "The Perfect World",
"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> ';
?>

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.