www.webdeveloper.com
Results 1 to 2 of 2

Thread: [RESOLVED] preventing duplicates in an array.

  1. #1
    Join Date
    Feb 2007
    Posts
    118

    resolved [RESOLVED] preventing duplicates in an array.

    first, here is the code.

    PHP Code:
    $array count($_POST[betNum]);
    $contents implode(", "$_POST[betNum]);
    echo (
    "You chose $array picks. Double check them now...$contents<br><br>");

    $i 0;

    while (
    $i != $_POST[howMany]) {

    $randSet array_rand(array_flip($_POST[betNum]), 10);

    $randSet implode(", "$randSet);

    echo(
    "$randSet<br><br>");

    $i++;



    possible solutions...

    because this is for personal use, i could simply sort the results with the dups staying on top, so when i see a duplicate, i simply press refresh.

    or..

    if the value already exists in the array, $randSet, dont add it, subtract from $i and have it cycle through until $howMany has been reached.


    all of your ideas and help will be greatly appreciated!
    Last edited by WebJoel; 09-18-2010 at 11:00 AM. Reason: title "er" to "re"
    Watch the news today, so you don't have to watch the history channel tomorrow.

    Chat | Games

  2. #2
    Join Date
    Feb 2007
    Posts
    118
    got it...

    if any one is interested...

    PHP Code:
    $array count($_POST[betNum]);
    $contents implode(", "$_POST[betNum]);
    echo (
    "You chose $array picks. Double check them now...$contents<br><br>");

    $i 0;
    $c 0;


    $finArray[] = 0;

    while (
    $i != $_POST[howMany]) {

    $randSet array_rand(array_flip($_POST[betNum]), 10);

    $randSet implode(", "$randSet);

    $checkDup in_array($randSet$finArray);

    $c++;

    if (!
    $checkDup) {

    $finArray[$i] = $randSet

    $i++;

    }

    else {

    $i $i-1;


    }



    }




    $result implode("<br>"$finArray);

    echo 
    "how many trys did it take? $c<br><br>";

    echo 
    $result
    Watch the news today, so you don't have to watch the history channel tomorrow.

    Chat | Games

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles