标签:style blog io ar color sp for 数据 on
<?php /** * 去除数组中重复数据 * by www.jbxue.com **/ $input = array("a" => "green","", "red","b" => "green", "","blue", "red","c" => "witer","hello","witer"); //$result = array_unique($input); //去除重复元素 $result = a_array_unique($input); //只留下单一元素 foreach($result as $aa) { echo $aa."<br />"; } function multi_unique($array) { foreach ($array as $k=>$na) $new[$k] = serialize($na); $uniq = array_unique($new); foreach($uniq as $k=>$ser) $new1[$k] = unserialize($ser); return ($new1); } function a_array_unique($array)//写的比较好 { $out = array(); foreach ($array as $key=>$value) { if (!in_array($value, $out)) { $out[$key] = $value; } } return $out; }
去除二重数组:
function a_array_unique($array)//写的比较好 { $word = $out = array(); foreach ($array as $key=>$value) { if (!in_array($value[‘word‘], $word)){ $out[$key] = $value; $word[$key] = $value[‘word‘]; } } return $out; }
标签:style blog io ar color sp for 数据 on
原文地址:http://www.cnblogs.com/zl0372/p/php_102.html