note 37266 deleted from function.in-array by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: Lee Benson 

----

If you're trying to compare a variable against several possible other variables, like this...

if ($var == 1 || $var == 2 || $var == 3 || $var == 4) {

    // do this

}

You can make your code a lot neater by doing this:

if (in_array($var,array(1,2,3,4))) {

  // do this

}

This way, you're not repeating the "$var == x ||" part of your expression over and over again.

If you've used MySQL's IN() function for searching on multiple values, you'll probably appreciate using this code in your PHP scripts.

Hope this helps a few people.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.