如何从preg_match_all生成的数组中删除重复项? [英] How do I remove duplicates from a preg_match_all generated array?
本文介绍了如何从preg_match_all生成的数组中删除重复项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从preg_match_all生成的数组中删除重复项?
How do I remove duplicates from a preg_match_all generated array?
Array
(
Array
(
'font-family: "Comic Sans";',
'font-weight: bold;',
'font-weight: normal;',
'font-family: "Comic Sans";',
'font-weight: normal;'
)
Array
(
'font-family',
'font-weight',
'font-weight',
'font-family',
'font-weight'
)
Array
(
'"Comic Sans"',
'bold',
'normal',
'"Comic Sans"',
'normal'
)
)
如您所见,有多个重复值。没有重复值的新数组应如下所示。
As you can see there are several duplicate values. The new array without the duplicate values should look like this.
Array
(
Array
(
font-family: "Comic Sans",
font-weight: bold,
font-weight: normal,
)
Array
(
font-family,
font-weight,
font-weight
)
Array
(
"Comic Sans",
bold,
normal
)
)
我知道我可以使用foreach来做到这一点,但是我敢肯定有一种更漂亮的方法可以实现这一结果。我忽略了什么?
I know I could do this with an foreach but I`m sure there is a much prettier way to accomplish this result. What do I overlook?
推荐答案
您可以通过以下方式做到:
You can do it via:
//$rgData comes from preg_match_all
$rgResult = array_map('array_unique', $rgData);
这篇关于如何从preg_match_all生成的数组中删除重复项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文