Example of removing repeated values from a php multi-dimensional array _ PHP Tutorial

Source: Internet
Author: User
Example of removing duplicate values from the php multi-dimensional array. Copy the code as follows :? Php $ json {rec_items: [{classes: Fantasy, gid: 6326585, author: I eat tomatoes, nid: 10079306, last_sort: 841, last_chapter_name: The code is as follows:


$ Json = '{

"Rec_items ":[
{
"Classes": "Fantasy ",
"Gid": 6326585,
"Author": "I eat tomatoes ",
"Nid": 10079306,
"Last_sort": 841,
"Last_chapter_name": "Chapter 6 of volume 25th ",
"Sub_count": 5364424,
"Novel_name": "Old Man ",
"Last_update_time": 1393679718826
},
{
"Classes": "Fantasy ",
"Gid": 6109786,
"Author": "Tang Jia San Shao ",
"Nid": 10079046,
"Last_sort": 1153,
"Last_chapter_name": "Chapter 381st starting action (in )",
"Sub_count": 3933876,
"Novel_name": "peerless tangmen ",
"Last_update_time": 1393681654511
},
{
"Classes": "Fantasy ",
"Gid": 10645516,
"Author": "Chen Dong ",
"Nid": 12649548,
"Last_sort": 478,
"Last_chapter_name": "Chapter 432nd returning daughter-in-law to the village ",
"Sub_count": 1422482,
"Novel_name": "Perfect World ",
"Last_update_time": 1393681655610
},
{
"Classes": "Fantasy ",
"Gid": 4711723,
"Author": "Only shrimp ",
"Nid": 12629406,
"Last_sort": 2603,
"Last_chapter_name": "Chapter 1 awakening! ",
"Sub_count": 2841630,
"Novel_name": "",
"Last_update_time": 1393605899300
},
{
"Classes": "Fantasy ",
"Gid": 3701669,
"Author": "Cang Xiaotian ",
"Nid": 8583556,
"Last_sort": 3427,
"Last_chapter_name": "Chapter 2225th Peacock King! ",
"Sub_count": 606473,
"Novel_name": "Wu qijiu Xiao ",
"Last_update_time": 1391279170831
},
{
"Classes": "Fantasy ",
"Gid": 8141499,
"Author": "Feng Lingxia ",
"Nid": 9212380,
"Last_sort": 2579,
"Last_chapter_name": "Chapter 7 ]",
"Sub_count": 3082857,
"Novel_name": "unique day ",
"Last_update_time": 1393677692614
}
],
"Cate_book_items ":[
{
"Classes": "Fantasy ",
"Gid": 4711723,
"Author": "Only shrimp ",
"Nid": 12629406,
"Last_sort": 2603,
"Last_chapter_name": "Chapter 1 awakening! ",
"Sub_count": 2841630,
"Novel_name": "",
"Last_update_time": 1393605899300
},
{
"Classes": "Fantasy ",
"Gid": 3701669,
"Author": "Cang Xiaotian ",
"Nid": 8583556,
"Last_sort": 3427,
"Last_chapter_name": "Chapter 2225th Peacock King! ",
"Sub_count": 606473,
"Novel_name": "Wu qijiu Xiao ",
"Last_update_time": 1391279170831
},
{
"Classes": "Fantasy ",
"Gid": 10645516,
"Author": "Chen Dong ",
"Nid": 12649548,
"Last_sort": 478,
"Last_chapter_name": "Chapter 432nd returning daughter-in-law to the village ",
"Sub_count": 1422482,
"Novel_name": "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'

';
print_r($data);
echo '
';
print_r(mult_unique($data));
echo '
';
?>

The http://www.bkjia.com/PHPjc/736828.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/736828.htmlTechArticle code is as follows :? Php $ json = '{"rec_items": [{"classes": "Fantasy", "gid": 6326585, "author": "My Tomato", "nid ": 10079306, "last_sort": 841, "last_chapter_name ":...

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.