如何在PHP中删除重复值? [英] How to remove duplicate values in PHP?

查看:121
本文介绍了如何在PHP中删除重复值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助。想从php中的数组中删除重复的值。

  $ categoryTotal回声144 125 262 108 351 177 266 269 270 268 309 144 125 262 238 108 

使用时:

  vardump()

我得到

  Array([0] => 144 [1] => 125 [2] => 262 [3] => 108 [4] = 351 [5] => 177 [6] => 266 [7] => 269 [8] => 270 [9] => 268 [10] => 309 [14] = > 238)

我用排序按升序对值排序:

  108 108 125 125 144 144 177 238 262 262 266 268 269 270 309 351 

,然后使用 $ categoryTotal = array_unique($ categoryTotal,SORT_NUMERIC); 几个值,如 309 351 消失。



想知道如何知道这个数组中的重复值。

解决方案

使用 a rray_unique()函数,如下所示:

  $ noDuplicates = array_unique($ categoriesTotal); 

这里的文档


I need help. Want to remove duplicate values from array in php.

$categoryTotal echoes 144 125 262 108 351 177 266 269 270 268 309 144 125 262 238 108

On using:

vardump() 

I get

Array ( [0] => 144 [1] => 125 [2] => 262 [3] => 108 [4] => 351 [5] => 177 [6] => 266 [7] => 269 [8] => 270 [9] => 268 [10] => 309 [14] => 238 ) 

I used sort to sort the values in ascending order I get:

108 108 125 125 144 144 177 238 262 262 266 268 269 270 309 351 

but then using $categoryTotal=array_unique($categoryTotal,SORT_NUMERIC); few values like 309 351 disappear.

Would like to know how to know out duplicate values from this array.

解决方案

Use the array_unique() function, like this:

$noDuplicates = array_unique($categoryTotal);

Docs here.

这篇关于如何在PHP中删除重复值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆