去重 本文最后更新于:2023年12月5日 晚上 JS 版本数组去重let arr = [2, 22, 2, 2]; let x = new Set(arr); console.log([...x]); PHP 版本数组去重$input = ["a" => "green", "red", "b" => "green", "blue", "red"]; //方法一 使用array_unique()函数 array_unique($input); print_r($input); //方法二 键值交换, 然后只取键 $res = array_flip($input); $res = array_keys($input); print_r($res); 补充 : 如何重建数组的索引 ? //使用array_values 返回数组的值并建立数字索引. PHP > 基础 #PHP 去重 http://blog.lujinkai.cn/PHP/基础/去重/ 作者 像方便面一样的男子 发布于 2020年12月11日 更新于 2023年12月5日 许可协议 PHP中的Exception,Error和Throwable 上一篇 强大的filter_var函数 下一篇