当前位置:网站首页>php中的二维数组去重
php中的二维数组去重
2022-07-02 06:23:00 【夜空の雪風】
前言
有时候在数据库进行join关联查询数据的时候会查询出一些重复的数据需要进行手动去重操作,避免返回到列表中出现重复的数据。
/** * 1.删除二维数组中相同项的数据,一般用于数据库查询结果中相同记录的去重操作 * 2.重置一下二维数组的索引 * @param array $_2d_array 二维数组,类似: * $tmpArr = array( * array('id' => 1, 'value' => '15046f5de5bb708e'), * array('id' => 1, 'value' => '15046f5de5bb708e'), * ); * @param string $unique_key 表示上述数组的 "id" 键,或者 "value" 键 * @return mixed */
function unique_2d_array_by_key($_2d_array, $unique_key)
{
$tmp_key[] = array();
foreach ($_2d_array as $key => &$item) {
if (is_array($item) && isset($item[$unique_key])) {
if (in_array($item[$unique_key], $tmp_key)) {
unset($_2d_array[$key]);
} else {
$tmp_key[] = $item[$unique_key];
}
}
}
//重置一下二维数组的索引
return array_slice($_2d_array, 0, count($_2d_array), false);
}
边栏推荐
- Stack (linear structure)
- js数组的常用的原型方法
- In depth study of JVM bottom layer (II): hotspot virtual machine object
- 20210306 reprint how to make TextEdit have background pictures
- CTF three count
- Sentry搭建和使用
- UEditor . Net version arbitrary file upload vulnerability recurrence
- DeprecationWarning: . ix is deprecated. Please use. loc for label based indexing or. iloc for positi
- CAD二次开发 对象
- No process runs when querying GPU, but the video memory is occupied
猜你喜欢

Latex 编译报错 I found no \bibstyle & \bibdata & \citation command

Sqli labs customs clearance summary-page3

Sqli-labs customs clearance (less18-less20)

CVE-2015-1635(MS15-034 )遠程代碼執行漏洞複現

Sqli labs customs clearance summary-page4

Linux MySQL 5.6.51 community generic installation tutorial

A preliminary study on ant group G6

Sqli-labs customs clearance (less15-less17)

Présence d'une panne de courant anormale; Problème de gestion de la fsck d'exécution résolu

Latex error: the font size command \normalsize is not defined problem solved
随机推荐
ModuleNotFoundError: No module named ‘jieba. analyse‘; ‘ jieba‘ is not a package
查询GPU时无进程运行,但是显存却被占用了
Selenium+msedgedriver+edge browser installation driver pit
Présence d'une panne de courant anormale; Problème de gestion de la fsck d'exécution résolu
Sqli-labs customs clearance (less6-less14)
【文献阅读与想法笔记13】 Unprocessing Images for Learned Raw Denoising
2020-9-23 use of QT timer qtimer class.
apt命令报证书错误 Certificate verification failed: The certificate is NOT trusted
2021-07-05C#/CAD二次开发创建圆弧(4)
DeprecationWarning: . ix is deprecated. Please use. loc for label based indexing or. iloc for positi
SQLI-LABS通关(less2-less5)
Review of reflection topics
js判断对象是否为空
Linux MySQL 5.6.51 Community Generic 安装教程
Latex compilation error I found no \bibstyle &\bibdata &\citation command
Flex Jiugongge layout
MySQL index
[self cultivation of programmers] - Reflection on job hunting Part II
Queue (linear structure)
UEditor . Net version arbitrary file upload vulnerability recurrence