php multidimensional array with duplicate values removed sample sharing

  • 2021-01-18 06:21:57
  • OfStack


<?php
$json='{
    "rec_items": [
        {
            "classes": " fantasy ",
            "gid": 6326585,
            "author": " I eat tomatoes ",
            "nid": 10079306,
            "last_sort": 841,
            "last_chapter_name": " The first 2105 volume   The first 6 chapter  1 And empty ",
            "sub_count": 5364424,
            "novel_name": " Mang shortage age ",
            "last_update_time": 1393679718826
        },
        {
            "classes": " fantasy ",
            "gid": 6109786,
            "author": " tang 3 less ",
            "nid": 10079046,
            "last_sort": 1153,
            "last_chapter_name": " The first 3 best 8101 chapter   Go into action (middle) ",
            "sub_count": 3933876,
            "novel_name": " Independent, tang door ",
            "last_update_time": 1393681654511
        },
        {
            "classes": " fantasy ",
            "gid": 10645516,
            "author": " Chen dong ",
            "nid": 12649548,
            "last_sort": 478,
            "last_chapter_name": " The first 4 best 3102 chapter   Carry his wife back to the village ",
            "sub_count": 1422482,
            "novel_name": " A perfect world ",
            "last_update_time": 1393681655610
        },
        {
            "classes": " fantasy ",
            "gid": 4711723,
            "author": " It's just shrimp ",
            "nid": 12629406,
            "last_sort": 2603,
            "last_chapter_name": " The first 2588 chapter   Wake up! ",
            "sub_count": 2841630,
            "novel_name": " Wu inverse ",
            "last_update_time": 1393605899300
        },
        {
            "classes": " fantasy ",
            "gid": 3701669,
            "author": " Pale smile day ",
            "nid": 8583556,
            "last_sort": 3427,
            "last_chapter_name": " Two thousand two hundred 2105 chapter   Peacock king! ",
            "sub_count": 606473,
            "novel_name": " Wu broken 9 clouds ",
            "last_update_time": 1391279170831
        },
        {
            "classes": " fantasy ",
            "gid": 8141499,
            "author": " The wind ling world ",
            "nid": 9212380,
            "last_sort": 2579,
            "last_chapter_name": " The first 5 best 2106 chapter  9 War of the Heavenly Emperor 7 】 ",
            "sub_count": 3082857,
            "novel_name": " such 9 Heavy day ",
            "last_update_time": 1393677692614
        }
    ],
    "cate_book_items": [
        {
            "classes": " fantasy ",
            "gid": 4711723,
            "author": " It's just shrimp ",
            "nid": 12629406,
            "last_sort": 2603,
            "last_chapter_name": " The first 2588 chapter   Wake up! ",
            "sub_count": 2841630,
            "novel_name": " Wu inverse ",
            "last_update_time": 1393605899300
        },
        {
            "classes": " fantasy ",
            "gid": 3701669,
            "author": " Pale smile day ",
            "nid": 8583556,
            "last_sort": 3427,
            "last_chapter_name": " Two thousand two hundred 2105 chapter   Peacock king! ",
            "sub_count": 606473,
            "novel_name": " Wu broken 9 clouds ",
            "last_update_time": 1391279170831
        },
        {
            "classes": " fantasy ",
            "gid": 10645516,
            "author": " Chen dong ",
            "nid": 12649548,
            "last_sort": 478,
            "last_chapter_name": " The first 4 best 3102 chapter   Carry his wife back to the village ",
            "sub_count": 1422482,
            "novel_name": " A 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>';
?>


Related articles: