php多维数组去掉重复值示例分享_PHP教程

WBOY
풀어 주다: 2016-07-13 10:36:58
원래의
900명이 탐색했습니다.

复制代码 代码如下:

$json='{

    "rec_items": [
        {
            "classes": "玄幻",
            "gid": 6326585,
            "author": "我吃西红柿",
            "nid": 10079306,
            "last_sort": 841,
            "last_chapter_name": "第二十五卷 第六章 一扫而空",
            "sub_count": 5364424,
            "novel_name": "莽荒纪",
            "last_update_time": 1393679718826
        },
        {
            "classes": "玄幻",
            "gid": 6109786,
            "author": "唐家三少",
            "nid": 10079046,
            "last_sort": 1153,
            "last_chapter_name": "第三百八十一章 开始行动(中)",
            "sub_count": 3933876,
            "novel_name": "绝世唐门",
            "last_update_time": 1393681654511
        },
        {
            "classes": "玄幻",
            "gid": 10645516,
            "author": "辰东",
            "nid": 12649548,
            "last_sort": 478,
            "last_chapter_name": "第四百三十二章 扛媳妇回村",
            "sub_count": 1422482,
            "novel_name": "完美世界",
            "last_update_time": 1393681655610
        },
        {
            "classes": "玄幻",
            "gid": 4711723,
            "author": "只是小虾米",
            "nid": 12629406,
            "last_sort": 2603,
            "last_chapter_name": "第2588章 苏醒!",
            "sub_count": 2841630,
            "novel_name": "武逆",
            "last_update_time": 1393605899300
        },
        {
            "classes": "玄幻",
            "gid": 3701669,
            "author": "苍笑天",
            "nid": 8583556,
            "last_sort": 3427,
            "last_chapter_name": "第两千两百二十五章 孔雀王!",
            "sub_count": 606473,
            "novel_name": "武破九霄",
            "last_update_time": 1391279170831
        },
        {
            "classes": "玄幻",
            "gid": 8141499,
            "author": "风凌天下",
            "nid": 9212380,
            "last_sort": 2579,
            "last_chapter_name": "第五百二十六章 九劫、天帝之战【七】",
            "sub_count": 3082857,
            "novel_name": "傲世九重天",
            "last_update_time": 1393677692614
        }
    ],
    "cate_book_items": [
        {
            "classes": "玄幻",
            "gid": 4711723,
            "author": "只是小虾米",
            "nid": 12629406,
            "last_sort": 2603,
            "last_chapter_name": "第2588章 苏醒!",
            "sub_count": 2841630,
            "novel_name": "武逆",
            "last_update_time": 1393605899300
        },
        {
            "classes": "玄幻",
            "gid": 3701669,
            "author": "苍笑天",
            "nid": 8583556,
            "last_sort": 3427,
            "last_chapter_name": "第两千两百二十五章 孔雀王!",
            "sub_count": 606473,
            "novel_name": "武破九霄",
            "last_update_time": 1391279170831
        },
        {
            "classes": "玄幻",
            "gid": 10645516,
            "author": "辰东",
            "nid": 12649548,
            "last_sort": 478,
            "last_chapter_name": "第四百三十二章 扛媳妇回村",
            "sub_count": 1422482,
            "novel_name": "完美世界",
            "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 '

';<br>print_r($data);<br>echo '<br>';<br>print_r(mult_unique($data));<br>echo '
로그인 후 복사
';
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/736828.htmlTechArticle复制代码 代码如下: ?php $json='{ "rec_items": [ { "classes": "玄幻", "gid": 6326585, "author": "我吃西红柿", "nid": 10079306, "last_sort": 841, "last_chapter_name":...
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!