#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    36
    Rep Power
    14
    How would I determine if any of 20 variables are equal to each other?

    ie I have var1, var2, var3, etc. I want to know if any of them are the same value. There has to be a way to do this but I'm not sure how.

    Preferrably, I'd like to know which ones are equal, but that's a minor, secondary concern.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    London/UK
    Posts
    91
    Rep Power
    14
    put all the values of your vars into an array and then use php4's in_array() function

    i.e. loop thru the vars and see if the value of $var_n is in equal to the value of everything in tha array

    hth

    bealers

    ------------------
    http://back-end.org
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    36
    Rep Power
    14
    Thanks, but what if my host only has php3? Am I out of luck?

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    London/UK
    Posts
    91
    Rep Power
    14
    if (!ereg("^4",phpversion())) {

    function in_array($needle,$haystack) {
    # we have this function in PHP4,

    for ($i=0; $i < count($haystack); $i++) {

    if ($haystack[$i] == $needle) {
    return true;
    }
    }
    }
    }

    ------------------
    http://back-end.org
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    36
    Rep Power
    14
    I'm still confused. How do I denote that the $needle value is any of the values in the array.

    I'm not trying to see if any of the values of the array equal a certain value, I want to know if they equal each other.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    36
    Rep Power
    14
    I created a roundabout way to see if one value of the array is equal to any of the others:

    for ($i=0; $i<count($team); $i++) {
    $c=($i+1);
    for ($c; $c<=count($team); $c++){
    if ($team[$i] == $team[$c]) {
    echo "Values Match<br>";
    }
    }
    }

    But I'm sure there has to be a better way.

Similar Threads

  1. Passing POST variables
    By rlorenzo in forum PHP Development
    Replies: 11
    Last Post: June 6th, 2004, 02:00 PM
  2. help with assigning variables, variable passing/ retrieval
    By pinkipodmini in forum PHP Development
    Replies: 0
    Last Post: February 13th, 2004, 09:40 PM
  3. Replies: 2
    Last Post: February 10th, 2004, 11:03 PM
  4. Help passing variables from a text file via include()
    By c4ctuz in forum PHP Development
    Replies: 4
    Last Post: October 14th, 2003, 08:00 AM
  5. functions and variables
    By uniopp in forum PHP Development
    Replies: 7
    Last Post: September 25th, 2003, 09:43 AM

IMN logo majestic logo threadwatch logo seochat tools logo