删除重复值从PHP中的数组中完全删除 [英] Remove duplicated values completely deleted from array in php
本文介绍了删除重复值从PHP中的数组中完全删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从数组中删除相同的值. 例如: 这是数组.
I want to remove the values from array which are same. For example: This is the array.
Array ( [0] => 1 [1] => 63 [2] => 1 )
核心php中是否有任何函数或某些东西,它们只能返回不重复的值,即具有索引号1的值并删除索引0和2 ,我想要结果
is there any function or something in core php which return me only the value which is not duplicate i.e value with index number 1 and delete index 0 and 2, I want the result
Array ( [1] => 63)
有什么办法吗?
推荐答案
您可以使用 array_count_values()检查计数是否大于1.
You can use array_filter() and array_count_values() to check the count is not greater then 1.
<?php
$data = [1, 63, 1];
$data = array_filter($data, function ($value) use ($data) {
return !(array_count_values($data)[$value] > 1);
});
print_r($data);
结果:
Array
(
[1] => 63
)
也可以与多个重复项一起使用: https://3v4l.org/eJSTY
Will also work fine with multiple dupes: https://3v4l.org/eJSTY
这篇关于删除重复值从PHP中的数组中完全删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文