开发者

How to search array for duplicates using a single array?

I am checking a list of 10 spots, each spot w/ 3 top users to see if a user is in an array before echoing and storing.

foreach($top_10['top_10'] as $top10)        //loop each spot
{
    $getuser = ltrim($top10['url'], " users/" );   //strip url

if ($usercount < 3) {
      if ((array_search($getuser, $array) !== true)) {

            echo $getuser;                              
            $array[$c++] = $getuser;

        }
        else {

            echo "duplicate <br /><br />";
        }

     }
    }

The problem I am having is that for every loop, it creates a multi-dimensional array for some reason which only allows array_search to search the current array and not all combined. I am wanting to store everything in the same $array. This is what I see after a print_r($array)

A开发者_如何学JAVArray ( [0] => 120728 [1] => 205247 ) Array ( [0] => 232123 [1] => 091928 )


There seems to be more to this code. As there are variables being called in it that aren't defined, such as $c, $usercount, etc.. And using array_search with the 2nd parameter of $array if it doesn't exist is not a good idea also. Since it seems like $array is being set within the if statement for this only.

And you don't seem to be using the $top10 value within the foreach loop at all..., why is this?

It would help to see more of the code for me to be able to help you.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜