开发者

How to detect duplicate php Array

I have this array:-

Array ( [0] => Prefectorial Board/Prefect/2011 [1] => Prefectorial Board/Head Prefect/2011 [2] => Class Positions/Head Prefect/2011 [3] => Prefectorial Board/Head Prefect/2011 ) 

How to detect this array have duplicate value and I want the participant to re-fill in his data.

I have try to use this method to detect:-

开发者_如何学编程
$max  = max(array_values($lr_str));
$keys = array_keys($lr_str, $max);

but it seem like not work for me.

any idea on this?

thanks for advance.


I do not know if I understand you correctly, but you can test the array has duplicated values by using this:

if (count($your_array) === count(array_unique($your_array)) {
    // array has no duplicated values
} else {
    // array has duplicated values - see compared arrays
}


Are you looking for array_unique?


You can use array_unique() to remove duplicate values. If no values were removed then the returned array should have the same number of items as the original:

if(count($lr_str) == count(array_unique($lr_str))){
    //tell participant to re=fill their data
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜