NiX: Variablen Abfrage mit mehreren Möglichkeiten

Hallo zusammen.

Wie kann ich dieses verkürzen?

if (($variable == "wert1") || ($variable == "wert2") || ($variable == "wert3")) {
  echo "do this";
} elseif (($variable == "wert4") || ($variable == "wert5") || ($variable == "wert6")) {
  echo "do this";
} elseif (($variable == "wert7") || ($variable == "wert8") || ($variable == "wert9")) {
  echo "do this";
} else {
  echo "do this";
}

Ich weis, dass man das irgendwie kürzen kann. Switch ist sicher ein guter Ansatz, aber da habe ich das Problem, das ich mehrere Werte überprüfen muss.

Weis da jemand gerade was?

Danke und Gruss,
NiX

  1. Hallo NiX.

    Ich weis, dass man das irgendwie kürzen kann. Switch ist sicher ein guter Ansatz, aber da habe ich das Problem, das ich mehrere Werte überprüfen muss.

    Dann solltest du dir das dritte Beispiel zu switch genauer anschauen.

    Einen schönen Sonntag noch.

    Gruß, Mathias

    --
    sh:( fo:} ch:? rl:( br: n4:~ ie:{ mo:| va:) de:> zu:} fl:( ss:) ls:[ js:|
    „It is required that HTML be a common language between all platforms. This implies no device-specific markup, or anything which requires control over fonts or colors, for example. This is in keeping with the SGML ideal.“
    [HTML Design Constraints: Logical Markup]