简体   繁体   中英

I'm trying to find a element in an array that not repeat

i have to do a function to find a number that not repeat in an array. It's simple but i have no idea for where begins.

function $returnUnique($arr) {
   
   
}

That's quite simple, you need array_filter and array_count_values :

$result = array_filter(array_count_values($array), function ($count)
{
    return $count === 1;
});

$result will contain all unique elements from your initial array.

array_search(1, array_count_values($arr))

will find an element (specifically, the first element) that is only found once in the array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM