这篇文章主要介绍了两种php去除二维数组的重复项方法,大家可以进行比较看哪一种更适合自己,需要的朋友可以参考下
php去掉二维数组的重复值的方法总结,具体代码如下:
方法一:
//二维数组去掉重复值 function array_unique_fb($array2D){ foreach ($array2D as $v){ $v=join(',',$v); //降维,也可以用implode,将一维数组转换为用逗号连接的字符串 $temp[]=$v; } $temp=array_unique($temp); //去掉重复的字符串,也就是重复的一维数组 foreach ($temp as $k => $v){ $temp[$k]=explode(',',$v); //再将拆开的数组重新组装 } return $temp; }
方法二:
//二维数组去掉重复值,并保留键值 function array_unique_fb($array2D){ foreach ($array2D as $k=>$v){ $v=join(',',$v); //降维,也可以用implode,将一维数组转换为用逗号连接的字符串 $temp[$k]=$v; } $temp=array_unique($temp); //去掉重复的字符串,也就是重复的一维数组 foreach ($temp as $k => $v){ $array=explode(',',$v); //再将拆开的数组重新组装 //下面的索引根据自己的情况进行修改即可 $temp2[$k]['id'] =$array[0]; $temp2[$k]['title'] =$array[1]; $temp2[$k]['keywords'] =$array[2]; $temp2[$k]['content'] =$array[3]; } return $temp2; }
两种php去除二维数组的重复项的方法,各有利弊,大家可以根据具体情况进行选择。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools