0

I want to select multiple value on the same variable in a if
like

if ($var == "1|3|5")
{ Echo'The var was 1,3 or 5';}

is this possible without the usual long way

$var == "1" or $var == "3" or $var == "5"

it should not contains the value like 13 in 113. It should check the hole variable in a string

Cœur
  • 37,241
  • 25
  • 195
  • 267
Lovntola
  • 1,409
  • 10
  • 31
  • 2
    If you strong the values in an array you could use `in_array`. If you store those in a string you could use it in `preg_match`. e.g. `if (preg_match('/^1|3|5$/', $var))` – chris85 Feb 05 '17 at 15:34
  • PERFECT that was im looking for ^ and $ with preg_match in front. Thx so much. – Lovntola Feb 05 '17 at 15:41
  • 1
    You actually should group the values. The anchors currently only affects the lead and closing value. `^(1|3|5)$`. – chris85 Feb 05 '17 at 15:42

0 Answers0