PHP 二维数组去重方法

php二维数组的去重策略,如果需要根据某字段去重(其他字段可能不一致),那么需要使用循环策略,如果去重的都是相同的(字段,值),那么可以用序列化方式。

$allComments = array_map('serialize', $allComments);
$allComments = array_unique($allComments);
$allComments = array_map('unserialize', $allComments);

此方法是将待去重数组序列化,去重,在反序列化,它去重的二维数组中的数据必须是字段和值都相同的数据。

posted @ 2014-04-04 11:32  ..孔雀翎..  阅读(540)  评论(0编辑  收藏  举报