网站首页 > 知识剖析 正文
php去除数组中的重复键值,需要使用array_unique()函数来对数组的键值进行去重。
array_unique() 函数:用于移除数组中重复的值。如果两个或更多个数组值相同,只保留第一个值,其他的值都被移除。
注释:被保留的数组将保持第一个数组项的键名类型。
Bash
<?php
header("content-type:text/html;charset=gbk");
$array = array("PHP","ASP","ASP","李雷博客","PHP","PHP博客");
var_dump($array);
$result = array_unique($array);
echo "删除重复元素后的数组:";
var_dump($result);
?>
输出结果:
Bash
array(6) {
[0]=>
string(3) "PHP"
[1]=>
string(3) "ASP"
[2]=>
string(3) "ASP"
[3]=>
string(8) "李雷博客"
[4]=>
string(3) "PHP"
[5]=>
string(7) "PHP博客"
}
删除重复元素后的数组:
array(4) {
[0]=>
string(3) "PHP"
[1]=>
string(3) "ASP"
[3]=>
string(8) "李雷博客"
[5]=>
string(7) "PHP博客"
}
- 上一篇: PHP 8:函数和方法
- 下一篇: PHP类来实现一个数组,它将去除数组中所有值的头尾空格
猜你喜欢
- 2024-11-20 laravel5.0在linux下解决.htaccess无效和去除index.php的问题
- 2024-11-20 面向对象之里式替换法则
- 2024-11-20 如何保证API接口安全?
- 2024-11-20 wamp怎么升级php版本
- 2024-11-20 Wordpress建站教程:去除修改管理员邮箱时的邮件验证步骤
- 2024-11-20 给PHP开发者的九条建议
- 2024-11-20 PHP 数学相关函数
- 2024-11-20 Update The PHP Version In XAMPP On Windows
- 2024-11-20 3分钟短文 | PHP 删除字符串最末一个字符,你用的什么方法?
- 2024-11-20 PHP使用mongo-php-library操作MongoDB数据库的方法
- 07-09带你看好玩的CSS-霓虹灯按钮(css霓虹灯效果的文字)
- 07-0910个冷门但非常实用前端开发者很少用的CSS规则
- 07-09大厂都在用的10个css高级技巧,我敢说你最多用过3个!不服来辩!
- 07-092025年Top30 CSS面试题及答案(css笔试题)
- 07-09ASP.NET Core Web API 接口限流(asp.net core web api教程)
- 07-09C# ASP.NET Core Web Api 与 MVC 模式下 body 参数传递,post 参数方式
- 07-09ASP.NET Core Web API 中的 JSON 修补程序
- 07-09Visual Studio Code安装C#开发工具包并编写ASP.NET Core Web应用
- 最近发表
-
- 带你看好玩的CSS-霓虹灯按钮(css霓虹灯效果的文字)
- 10个冷门但非常实用前端开发者很少用的CSS规则
- 大厂都在用的10个css高级技巧,我敢说你最多用过3个!不服来辩!
- 2025年Top30 CSS面试题及答案(css笔试题)
- ASP.NET Core Web API 接口限流(asp.net core web api教程)
- C# ASP.NET Core Web Api 与 MVC 模式下 body 参数传递,post 参数方式
- ASP.NET Core Web API 中的 JSON 修补程序
- Visual Studio Code安装C#开发工具包并编写ASP.NET Core Web应用
- 深入了解 ASP.NET Core 中的 IWebHostEnvironment 接口
- ASP.NET WebForms功能增强(三)(asp net web)
- 标签列表
-
- xml (46)
- css animation (57)
- array_slice (60)
- htmlspecialchars (54)
- position: absolute (54)
- datediff函数 (47)
- array_pop (49)
- jsmap (52)
- toggleclass (43)
- console.time (63)
- .sql (41)
- ahref (40)
- js json.parse (59)
- html复选框 (60)
- css 透明 (44)
- css 颜色 (47)
- php replace (41)
- css nth-child (48)
- min-height (40)
- xml schema (44)
- css 最后一个元素 (46)
- location.origin (44)
- table border (49)
- html tr (40)
- video controls (49)