我有一个这样的数组数组:
Array
(
[userId] => 35
[fieldId] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 1
[4] => 2
[5] => 2
[6] => 1
[7] => 4
)
[educationTitle] => Array
(
[0] => School1
[1] => School2
[2] => 3
[3] => School1
[4] => School2
[5] => School2
[6] => School1
[7] =>
)
)
我想删除每个数组的所有重复项。所以,我希望最终的数组看起来像这样:
Array
(
[userId] => 35
[fieldId] => Array
(
[0] => 1
[1] => 2
[2] => 3
[7] => 4
)
[educationTitle] => Array
(
[0] => School1
[1] => School2
[2] => 3
[7] =>
)
)
我已经尝试过了(如此答案https://stackoverflow.com/a/307701/1009116中所建议的那样):
function multi_unique($updates) {
foreach ($updates as $k=>$na)
$new[$k] = serialize($na);
$uniq = array_unique($new);
foreach($uniq as $k=>$ser)
$new1[$k] = unserialize($ser);
return ($new1);
}
而且没有效果
我也试过这个(这里推荐 - https://stackoverflow.com/a/946300/1009116)
$input = array_map("unserialize", array_unique(array_map("serialize", $input)));
这只是返回最后一个数组(但是,它应该被过滤)
我究竟做错了什么???