Professional Web Applications Themes

if statement - PHP Development

I have an "if" statement that I would like to make a little bit more generic. This is how the statement looks now. if($k2b=="/etc/bind/options.conf.wp" || $k2b=="/etc/bind/rndc.conf.wp" || $k2b=="/etc/bind/keys.conf.wp"){ do this1 }else{ do this2 } What I would like to do is to have an array earlier in the script of just the items that it is checking for so that it can be more easily changed if I put this out as free or shareware software. Here is what it might look like, but I know that if this is possible, it probably won't look at all like this: $array=("/etc/bind/options.conf.wp","/etc/bind/rndc.conf.wp","/etc/bind/keys.conf.wp"); ...

  1. #1

    Default if statement

    I have an "if" statement that I would like to make a little bit more
    generic. This is how the statement looks now.

    if($k2b=="/etc/bind/options.conf.wp" || $k2b=="/etc/bind/rndc.conf.wp" ||
    $k2b=="/etc/bind/keys.conf.wp"){
    do this1
    }else{
    do this2
    }

    What I would like to do is to have an array earlier in the script of just
    the items that it is checking for so that it can be more easily changed if
    I put this out as free or shareware software. Here is what it might look
    like, but I know that if this is possible, it probably won't look at all
    like this:

    $array=("/etc/bind/options.conf.wp","/etc/bind/rndc.conf.wp","/etc/bind/keys.conf.wp");
    if($k2b==$array){
    do this1
    }else{
    do this2
    }

    I think that might make enough since to see if someone can help me on
    this. This would be real nice for me in use in a lot of scripts.

    Thanks
    Steve

    PHP / MySQL
    Steve Guest

  2. #2

    Default Re: [PHP] if statement

    Steve Buehler wrote:

    [snip]
     

    You are close. Check out in_array(). http://us4.php.net/in_array

    if (in_array($kb2, $array))

    - Brad
    Brad Guest

  3. #3

    Default Re: [PHP] if statement

    if(in_array($k2b, $array)) { ...

    Steve Buehler wrote:
     
    Marek Guest

  4. #4

    Default Re: [PHP] if statement

    * Thus wrote Steve Buehler (com): 

    Close, but not close enough :)

    if (in_array($k2b, $array) ) {
    // do this1
    }

    http://php.net/in_array

    Although depending on the situation I usually set up array's of
    this type like this:

    $arr = array(
    '/etc/bind/options.conf.wp' => true,
    '/etc/bind/rndc.conf.wp' => true
    );

    Then my condition is:

    if ($arr[$k2b]) {
    // do this1
    }


    Curt
    --
    "I used to think I was indecisive, but now I'm not so sure."
    Curt Guest

  5. #5

    Default Re: [PHP] if statement

    To Brad, Marek and Curt (and anybody who responds after this)
    Thank you so much for your help. This is going to help me out so
    much in a lot of my scripts. It will sure make them a little.....No....a
    LOT more portable now.

    Thanks
    Steve

    At 11:26 AM 9/30/2003, you wrote: 
    >
    >You are close. Check out in_array(). http://us4.php.net/in_array
    >
    >if (in_array($kb2, $array))
    >
    >- Brad[/ref]
    Steve Guest

Similar Threads

  1. Need help with a WHERE statement
    By Shane930 in forum Coldfusion Database Access
    Replies: 4
    Last Post: November 9th, 10:47 PM
  2. Help with an IF THEN statement
    By oppels in forum Dreamweaver AppDev
    Replies: 4
    Last Post: May 16th, 12:10 PM
  3. if statement with url
    By John in forum PHP Development
    Replies: 5
    Last Post: September 11th, 03:13 AM
  4. IIF statement
    By Andrew Smith in forum Microsoft Access
    Replies: 3
    Last Post: July 9th, 03:50 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139