SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: IF without end?

  1. #1
    SitePoint Zealot doca's Avatar
    Join Date
    Dec 2004
    Location
    Vienna, AT
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IF without end?

    Hello
    How to make this code smaller? This OR without end Make Me Nervous. Is it possible to make this as array, and how?

    PHP Code:
    if ($wapsub=="XX" OR $wapsub=="XL" OR $wapsub=="XS" OR $wapsub=="XM" OR $wapsub=="XD" OR $wapsub=="XR" OR $wapsub=="FT"$subkeyword "$wapsub"

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $arr = array('XX','XL','XS','XM','XD','XR','FT');
    foreach (
    $arr as $item) {
      if (
    $wapsub == $item) {
        
    $subkeyword $wapsub//no need for double quotes around a variable
      
    }

    or
    PHP Code:
    $arr = array('XX','XL','XS','XM','XD','XR','FT');
    $key array_search($wapsub$arr);
    $subkeyword $arr[$key]; 
    or
    PHP Code:
    $arr = array('XX','XL','XS','XM','XD','XR','FT');
    $wapsub = array($wapsub);
    $result array_intersect($arr$wapsub);
    $subkeyword $result[0]; 
    The second one is best I think.

  3. #3
    SitePoint Zealot doca's Avatar
    Join Date
    Dec 2004
    Location
    Vienna, AT
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah thanks man

  4. #4
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    or

    PHP Code:
    $arr = array('XX','XL','XS','XM','XD','XR','FT');
    if(
    in_array($wapsub,$arr))$subkeyword "$wapsub"
    Saul

  5. #5
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Even better!


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
  •