php多维数组怎么去除重复值
php多维数组去除重复值
1、实现多维数组去除重复值的函数
function array_unique_new($arr) { $t = array_map('serialize', $arr); //利用serialize()方法将数组转换为以字符串形式的一维数组 $t = array_unique($t); //去掉重复值 $new_arr = array_map('unserialize', $t); //然后将刚组建的一维数组转回为php值 return $new_arr; }
2、需要去除重复值的数组
$arr = array( array('sup_name' => '上海', 'cn_name' => 'EthylAcetate', 'en_name' => '乙酸乙酯1', 'pinyin' => 'yisuanyizhi', 'pro_info' => '耗材', ), array('sup_name' => '上海2', 'cn_name' => 'EthylAcetate', 'en_name' => '乙酸乙酯2', 'pinyin' => 'yisuanyizhi', 'pro_info' => '耗材', ), array('sup_name' => '上海4', 'cn_name' => 'EthylAcetate', 'en_name' => '乙酸乙酯1', 'pinyin' => 'yisuanyizhi', 'pro_info' => '耗材', ), array('sup_name' => '上海', 'cn_name' => 'EthylAcetate', 'en_name' => '乙酸乙酯3', 'pinyin' => 'yisuanyizhi', 'pro_info' => '耗材', ), array('sup_name' => '上海1', 'cn_name' => 'EthylAcetate', 'en_name' => '乙酸乙酯4', 'pinyin' => 'yisuanyizhi', 'pro_info' => '耗材', ), array('sup_name' => '上海', 'cn_name' => 'EthylAcetate', 'en_name' => '乙酸乙酯3', 'pinyin' => 'yisuanyizhi', 'pro_info' => '耗材', ), array('sup_name' => '上海1', 'cn_name' => 'EthylAcetate', 'en_name' => '乙酸乙酯4', 'pinyin' => 'yisuanyizhi', 'pro_info' => '耗材', ), );
输出看看:
3、执行测试
$new_arr = array_unique_new($arr); echo ''; print_r($new_arr);
以上就是php多维数组怎么去除重复值的详细内容,更多请关注毛票票其它相关文章!