php array_push() -> How not to push if the array already contains the value

前端 未结 9 1959
无人共我
无人共我 2020-12-29 01:04

I am using the following loop to add items to an an array of mine called $liste. I would like to know if it is possible somehow not to add $value to the $liste array if the

9条回答
  •  醉话见心
    2020-12-29 01:55

    maybe you want to use it as an associative array instead. it's implemented as (something like) a hash table, so you get constant insert time instead of linear.

    function find_uniq( $something ) {
        foreach($something as $value){
             $liste[$value]++;
        }
        return array_keys( $liste );
    }
    

提交回复
热议问题