PHP 从多维数组中删除重复值 [英] PHP remove duplicate values from multidimensional array
本文介绍了PHP 从多维数组中删除重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们可以使用array_unique()
从php中的单个多维数组中删除重复条目.是否可以与多维数组一起使用?它不适合我!
We can use array_unique()
for remove duplicate entry from a single multidimensional array in php.Is it possible to use with multidimensional array? It is not working for me!
这是数组的样子
Array (
[0] => Array ( [0] => 1001 [1] => john [2] => example )
[1] => Array ( [0] => 1002 [1] => test [2] => dreamz )
[2] => Array ( [0] => 1001 [1] => john [2] => example )
[3] => Array ( [0] => 1001 [1] => example [2] => john )
[4] => Array ( [0] => 1001 [1] => john [2] => example )
)
任何人都可以帮我...
Anybody can please help me...
推荐答案
用户对 array_unique 的评论页面确实对此有所了解.您很可能会在这些评论中找到一些隐藏的宝石 - 这是一个非常方便的文档.
The user comments on the array_unique page do shed some light on this. You will most likely find some hidden gems in those comments - its a very handy documentation.
通过快速浏览器显示以下内容以从多维数组中删除重复项:
Just a quick browser through revealed the following to remove duplicates from a multi dimensional array:
<?php
function super_unique($array)
{
$result = array_map("unserialize", array_unique(array_map("serialize", $array)));
foreach ($result as $key => $value)
{
if ( is_array($value) )
{
$result[$key] = super_unique($value);
}
}
return $result;
}
?>
这篇关于PHP 从多维数组中删除重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文