jiaxp 发表于 2017-4-7 11:58:56

php排除重复数组与排除重复字符串

  <?php function uniqueByChild($array, $child){$child = "['" . implode("']['", explode(',', $child)) . "']";$buffer = array();foreach($array as $index => $value){eval("/$check = /$value{$child};");if(in_array($check, $buffer)){unset($array[$index]);}else{$buffer[] = $check;}}return $array;}$string="33,33,22,22,11,99,00,88,44,55,44,33";$array=explode(",", $string);$array2 = uniqueByChild($array,'');echo(implode(',',$array2));?>
  输入:
  33,33,22,22,11,99,00,88,44,55,44,33
  输出结果:
  33,22,11,99,00,88,44,55
页: [1]
查看完整版本: php排除重复数组与排除重复字符串