当前位置:网站首页>Two dimensional array de duplication in PHP
Two dimensional array de duplication in PHP
2022-07-02 07:28:00 【Snow wind in the night sky】
Preface
Sometimes in the database join When associating and querying data, some duplicate data will be found, which requires manual de duplication , Avoid returning to the list with duplicate data .
/** * 1. Delete the data of the same item in the two-dimensional array , It is generally used for de duplication of the same records in the database query results * 2. Reset the index of the two-dimensional array * @param array $_2d_array Two dimensional array , similar : * $tmpArr = array( * array('id' => 1, 'value' => '15046f5de5bb708e'), * array('id' => 1, 'value' => '15046f5de5bb708e'), * ); * @param string $unique_key Representing the above array "id" key , perhaps "value" key * @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];
}
}
}
// Reset the index of the two-dimensional array
return array_slice($_2d_array, 0, count($_2d_array), false);
}
边栏推荐
- 生成模型与判别模型的区别与理解
- 【Ranking】Pre-trained Language Model based Ranking in Baidu Search
- Play online games with mame32k
- A summary of a middle-aged programmer's study of modern Chinese history
- CSRF attack
- MapReduce concepts and cases (Shang Silicon Valley Learning Notes)
- @Transational踩坑
- SSM laboratory equipment management
- Interpretation of ernie1.0 and ernie2.0 papers
- ERNIE1.0 与 ERNIE2.0 论文解读
猜你喜欢
Oracle EBS数据库监控-Zabbix+zabbix-agent2+orabbix
ORACLE EBS 和 APEX 集成登录及原理分析
ssm人事管理系统
【信息检索导论】第二章 词项词典与倒排记录表
【模型蒸馏】TinyBERT: Distilling BERT for Natural Language Understanding
Principle analysis of spark
Proteus -- RS-232 dual computer communication
[introduction to information retrieval] Chapter 1 Boolean retrieval
软件开发模式之敏捷开发(scrum)
使用MAME32K进行联机游戏
随机推荐
【调参Tricks】WhiteningBERT: An Easy Unsupervised Sentence Embedding Approach
Oracle EBS ADI development steps
叮咚,Redis OM对象映射框架来了
【BERT,GPT+KG调研】Pretrain model融合knowledge的论文集锦
Oracle EBS interface development - quick generation of JSON format data
Explanation of suffix of Oracle EBS standard table
Yaml file of ingress controller 0.47.0
聊天中文语料库对比(附上各资源链接)
类加载器及双亲委派机制
Oracle apex Ajax process + dy verification
Classloader and parental delegation mechanism
Calculate the difference in days, months, and years between two dates in PHP
Use matlab to realize: chord cut method, dichotomy, CG method, find zero point and solve equation
Optimization method: meaning of common mathematical symbols
[medical] participants to medical ontologies: Content Selection for Clinical Abstract Summarization
【信息检索导论】第一章 布尔检索
Cognitive science popularization of middle-aged people
ssm垃圾分类管理系统
view的绘制机制(三)
ORACLE EBS ADI 开发步骤