SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict next2heaven's Avatar
    Join Date
    Apr 2005
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Simpler way for this IF statement?

    If I want to check a variable against a list of values is their an easier way than this:

    if ($temp != 1 && $temp !=2 && $temp !=6) ....

    Is there some statement that is simpler like the following?

    if ($temp != list(1,2,6)) ....

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Location
    Bel Air, Maryland.
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe...

    PHP Code:
    $checkList = array("apple""orange""pear");

    if (
    in_array($theVar$checkList)) {
        do 
    stuff here...

    and in_array is case sensitive.
    ---
    Paul S. Smith
    technetic | design & code

  3. #3
    SitePoint Addict next2heaven's Avatar
    Join Date
    Apr 2005
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay...cool...so I just did:

    if(in_array($theVar, explode(",",$checkList))){ ....

    Nice...thanks!


Bookmarks

Posting Permissions

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