我有一个多维数组:
Array
(
[0] => Array
(
[a] => 1
[b] => 2
[c] => 3
[d] => 4
)
[1] => Array
(
[a] => 1
[b] => 5
[c] => 3
[d] => 4
)
[2] => Array
(
[a] => 1
[b] => 2
[c] => 3
[d] => 4
)
)
查看第一个索引(或零)和第三个索引(第二个索引),a、b、c、d 中的值等于 1、2、3、4。假设数组相等,或者它们没有区别;我的问题是,我怎样才能捕捉到相等的数组,我的目的是向用户展示重复的值输入,
我已经在使用 array_unique
。这是结果:
Array
(
[0] => Array
(
[a] => 1
[b] => 2
[c] => 3
[d] => 4
)
[1] => Array
(
[a] => 1
[b] => 5
[c] => 3
[d] => 4
)
)
但我只想得到重复的数据,而不是去除重复的数据。
// first : get all data, if the data same / duplicate take only one data
$unique = array_unique($data, SORT_REGULAR);
// then, get the data which duplicate with
$diffCellUniq = array_diff_key($data, $unique);
// so print the result
print_r($diffCellUniq); exit;
Array
(
[2] => Array
(
[a] => 1
[b] => 2
[c] => 3
[d] => 4
)
)
最佳答案
// first : get all data, if the data same / duplicate take only one data
$unique = array_unique($data, SORT_REGULAR);
// then, get the data which duplicate with
$diffCellUniq = array_diff_key($data, $unique);
// so print the result
print_r($diffCellUniq); exit;
Array
(
[2] => Array
(
[a] => 1
[b] => 2
[c] => 3
[d] => 4
)
)
关于php - 如何在 php 中获取重复的多维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39222346/