Multiple Options

triumph

69.***.***.***
1,379 days ago

Multiple Options

One thing I struggle with is doing things in a more simple way, especially when I have multiple items to do:

for example I have 20 conditions to check on and will do this:

Code:


$thumb = "all good men eat eggs";
$redoor = "all good men eat pancakes";
$adpos = strpos($kwin,'test1');
if ($adpos !== false) { $redoor = $thumb; }
$adpos = strpos($kwin,'test2');
if ($adpos !== false) { $redirect = $thumb; }



In some cases I want it to be : If I find "test1", "test2", "test3" in $kwin, I want to set $redoor = $thumb. I also might want to set $redoor = $thumb2 if $kwin = "test4", "test5", "test6".

As it stands right now, I am just having a seperate set of lines for each condition, but that seems sloppy when I have 30-40 different strings to check for. Is there a cleaner way to do this?

Bradd

203.***.***.***
1,377 days ago

triumph;308:

One thing I struggle with is doing things in a more simple way, especially when I have multiple items to do:

for example I have 20 conditions to check on and will do this:

Code:


$thumb = "all good men eat eggs";
$redoor = "all good men eat pancakes";
$adpos = strpos($kwin,'test1');
if ($adpos !== false) { $redoor = $thumb; }
$adpos = strpos($kwin,'test2');
if ($adpos !== false) { $redirect = $thumb; }



In some cases I want it to be : If I find "test1", "test2", "test3" in $kwin, I want to set $redoor = $thumb. I also might want to set $redoor = $thumb2 if $kwin = "test4", "test5", "test6".

As it stands right now, I am just having a seperate set of lines for each condition, but that seems sloppy when I have 30-40 different strings to check for. Is there a cleaner way to do this?


i think you should use some arraylists to sove this problem and you can apply if-then-else statments in more sophisticated way and that is some good approach rather than writing too long code