我有一个多维数组:
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
)
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句