目录
php排除有某同一特征的数据
php
想用foreach来获取gid, 得到以下的数据:gid 相同,
有什么办法排除同样的gid,一样的gid,只留一组.
<code>[ { "id": "151", "uid": "101497", "gid": "399", "create_time": "1462445116", "msg": null, "number": "148", "order_id": "2016050518451705537", "type": "0", "prepay_id": null, "code": null, "recharge": "0", "wid": "0", "end_time": "1462445416", "status": "1" }, { "id": "132", "uid": "101497", "gid": "399", "create_time": "1462420981", "msg": null, "number": "97", "order_id": "2016050512030120339", "type": "0", "prepay_id": null, "code": null, "recharge": "0", "wid": "0", "end_time": "1462421281", "status": "1" }, { "id": "133", "uid": "101497", "gid": "399", "create_time": "1462426436", "msg": null, "number": "97", "order_id": "2016050513335645342", "type": "0", "prepay_id": null, "code": null, "recharge": "0", "wid": "0", "end_time": "1462426736", "status": "1" } ]</code>
登录后复制
登录后复制
回复内容:
想用foreach来获取gid, 得到以下的数据:gid 相同,
有什么办法排除同样的gid,一样的gid,只留一组.
<code>[ { "id": "151", "uid": "101497", "gid": "399", "create_time": "1462445116", "msg": null, "number": "148", "order_id": "2016050518451705537", "type": "0", "prepay_id": null, "code": null, "recharge": "0", "wid": "0", "end_time": "1462445416", "status": "1" }, { "id": "132", "uid": "101497", "gid": "399", "create_time": "1462420981", "msg": null, "number": "97", "order_id": "2016050512030120339", "type": "0", "prepay_id": null, "code": null, "recharge": "0", "wid": "0", "end_time": "1462421281", "status": "1" }, { "id": "133", "uid": "101497", "gid": "399", "create_time": "1462426436", "msg": null, "number": "97", "order_id": "2016050513335645342", "type": "0", "prepay_id": null, "code": null, "recharge": "0", "wid": "0", "end_time": "1462426736", "status": "1" } ]</code>
登录后复制
登录后复制
$str='[ { "id": "151", "uid": "101497", "gid": "399", "create_time": "1462445116", "msg": null, "number": "148", "order_id": "2016050518451705537", "type": "0", "prepay_id": null, "code": null, "recharge": "0", "wid": "0", "end_time": "1462445416", "status": "1" }, { "id": "132", "uid": "101497", "gid": "399", "create_time": "1462420981", "msg": null, "number": "97", "order_id": "2016050512030120339", "type": "0", "prepay_id": null, "code": null, "recharge": "0", "wid": "0", "end_time": "1462421281", "status": "1" }, { "id": "133", "uid": "101497", "gid": "398", "create_time": "1462426436", "msg": null, "number": "97", "order_id": "2016050513335645342", "type": "0", "prepay_id": null, "code": null, "recharge": "0", "wid": "0", "end_time": "1462426736", "status": "1" } ]'; $arr = json_decode($str,1); $res = []; foreach($arr as $v){ if (!isset($res[$v['gid']])){ $res[$v['gid']] = $v; } } echo '<pre class="brush:php;toolbar:false">';print_r(array_values($res));
登录后复制
自己写个函数去除重复的数据在遍历啊
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前
By 尊渡假赌尊渡假赌尊渡假赌
击败分裂小说需要多长时间?
1 个月前
By DDD
R.E.P.O.保存文件位置:在哪里以及如何保护它?
1 个月前
By DDD
R.E.P.O.最佳图形设置
2 周前
By 尊渡假赌尊渡假赌尊渡假赌
刺客信条阴影:贝壳谜语解决方案
1 周前
By DDD

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

PHP 8.4 带来了多项新功能、安全性改进和性能改进,同时弃用和删除了大量功能。 本指南介绍了如何在 Ubuntu、Debian 或其衍生版本上安装 PHP 8.4 或升级到 PHP 8.4

CakePHP 是 PHP 的开源框架。它的目的是使应用程序的开发、部署和维护变得更加容易。 CakePHP 基于类似 MVC 的架构,功能强大且易于掌握。模型、视图和控制器 gu
