网络编程 
首页 > 网络编程 > 浏览文章

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

(编辑:jimmy 日期: 2024/11/19 浏览:3 次 )

复制代码 代码如下:
<?php
$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 '<pre>';
print_r($data);
echo '<br>';
print_r(mult_unique($data));
echo '</pre>';
?>

上一篇:php通过字符串调用函数示例
下一篇:PHP 函数call_user_func和call_user_func_array用法详解
一句话新闻
一文看懂荣耀MagicBook Pro 16
荣耀猎人回归!七大亮点看懂不只是轻薄本,更是游戏本的MagicBook Pro 16.
人们对于笔记本电脑有一个固有印象:要么轻薄但性能一般,要么性能强劲但笨重臃肿。然而,今年荣耀新推出的MagicBook Pro 16刷新了人们的认知——发布会上,荣耀宣布猎人游戏本正式回归,称其继承了荣耀 HUNTER 基因,并自信地为其打出“轻薄本,更是游戏本”的口号。
众所周知,寻求轻薄本的用户普遍更看重便携性、外观造型、静谧性和打字办公等用机体验,而寻求游戏本的用户则普遍更看重硬件配置、性能释放等硬核指标。把两个看似难以相干的产品融合到一起,我们不禁对它产生了强烈的好奇:作为代表荣耀猎人游戏本的跨界新物种,它究竟做了哪些平衡以兼顾不同人群的各类需求呢?